Search code examples
c#asp.netajaxupdatepanelradiobuttonlist

Why my radio button list fires only when the selected value = 1


I don't know why my radiobuttonlist fires only when i select the second list item !

My aspx :

    <asp:Panel ID="pnl_select_sign" runat="server" Visible="false">
            <asp:RadioButtonList ID="rb_select_sign" runat="server" AutoPostBack="true" RepeatDirection="Horizontal"
                OnSelectedIndexChanged="rb_select_sign_SelectedIndexChanged" CausesValidation="false" AppendDataBoundItems="true">
                <asp:ListItem Selected="True" Value="0">normal</asp:ListItem>
                <asp:ListItem Value="1">abnormal</asp:ListItem>
            </asp:RadioButtonList>
    </asp:Panel> 
  <div class="events" dir="rtl">
        <fieldset>
            <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                <ContentTemplate>
                    <asp:Panel ID="pnl_PageNew_UC" runat="server" Width="100%">
                    </asp:Panel>
                    <asp:Panel ID="pnl_sign" runat="server" Width="100%" Visible="false">
                    </asp:Panel>
                </ContentTemplate>
                <Triggers>
                    <asp:AsyncPostBackTrigger ControlID="rb_select_sign" EventName="SelectedIndexChanged" />
                </Triggers>
            </asp:UpdatePanel>
        </fieldset>
    </div>

My .cs :

 protected void rb_select_sign_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (rb_select_sign.SelectedValue == "0")
            {
                pnl_PageNew_UC.Visible = true;
                pnl_sign.Visible = false;

            }
            else
            {
                pnl_PageNew_UC.Visible = false;
                pnl_sign.Visible = true;

            }
        }

Solution

  • Well, your problem starts not when the selectedvalue =1, it starts as soon as you set the visibility of the panels to true.

    The problem itself is in your AsyncPostBackTrigger, your trigger is outside the UpdatePanel and therefore no longer triggered.

    This can easily be solved, put the RadioButtonList inside the ContentTemplate:

    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
      <ContentTemplate>
        <asp:Panel ID="pnl_select_sign" runat="server" >
            <asp:RadioButtonList ID="rb_select_sign" runat="server" AutoPostBack="true" RepeatDirection="Horizontal" ... />
        </asp:Panel> 
        <asp:Panel ID="pnl_PageNew_UC" runat="server" Width="100%">
        </asp:Panel>
    ....