MS Ajax: RadioButton CheckedChanged not firing back with AJAX v1.0?

I saw a very interesting post on the Ajax forum. NXTwoThou had a problem with 2 radiobutton controls which must fire the OnCheckedChanged event. Here is the code.

        <script runat=”Server”>
            protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack)
                    ddl_customers_specific.Items.Add(new ListItem(“Test”));
            }
            protected void rb_customers_all_CheckedChanged(object sender, EventArgs e)
            {
                ddl_customers_specific.BackColor = System.Drawing.Color.Red;
            }
            protected void rb_customers_specific_CheckedChanged(object sender, EventArgs e)
            {
                ddl_customers_specific.BackColor = System.Drawing.Color.Blue;
            }
        </script>
        <form id=”form1″ runat=”server”>
            <asp:ScriptManager runat=”server” ID=”sm” />
                 <asp:RadioButton ID=”rb_customers_all” runat=”server” Text=”All Customers” AutoPostBack=”true”
                 Checked=”true” GroupName=”g_Customers” OnCheckedChanged=”rb_customers_all_CheckedChanged” />        
    <asp:RadioButton ID=”rb_customers_specific” runat=”server” Text=”Specific Customers” AutoPostBack=”true” GroupName=”g_Customers” OnCheckedChanged=”rb_customers_specific_CheckedChanged” />
    <asp:UpdatePanel ID=”up_customer” runat=”server” UpdateMode=”conditional”>
                   <ContentTemplate>
                          <asp:DropDownList ID=”ddl_customers_specific” runat=”server” />
                   </ContentTemplate>
                   <Triggers>
                          <asp:AsyncPostBackTrigger ControlID=”rb_customers_all” EventName=”CheckedChanged” />
                          <asp:AsyncPostBackTrigger ControlID=”rb_customers_specific” EventName=”CheckedChanged” />
                   </Triggers>
              </asp:UpdatePanel>
         </form>

     

The problem is that the radio button “rb_customers_all” has the property checked set to true. When this is set to true the event will never get fired. removing this property and adding the following code “rb_customers_all.InputAttributes["checked"] = “true”;” will fix this problem.

Have fun!

Follow

Get every new post delivered to your Inbox.