2012-12-30 55 views
0

我不知道爲什麼我的radiobuttonlist僅在我選擇第二個列表項時觸發!爲什麼我的單選按鈕列表僅在所選值= 1時觸發

我的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> 

我的.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; 

      } 
     } 

回答

1

嗯,你的問題開始不能當selectedvalue =1,它只要你面板的可見性設置爲true開始。

問題本身就在你的AsyncPostBackTrigger,你的觸發器是以外的這個UpdatePanel因此不再被觸發。

這可以很容易解決的,把單選按鈕列表中的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> 
.... 
+0

我恨更新面板:(:( 慘了微軟的AJAX !! –

+1

有時你不能把所有控件的更新因爲頁面設計 – phnkha

+1

@just_name我同意,這很煩人 - 但過了一段時間,你開始得到它的手... :) – Blachshma

1

試試這個代碼:

<asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional"> 
     <ContentTemplate> 
      <asp:Panel ID="pnl_select_sign" runat="server"> 
       <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> 
     </ContentTemplate> 
    </asp:UpdatePanel> 

    <div class="events" dir="rtl"> 
     <fieldset> 
      <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional"> 
       <ContentTemplate> 
        <asp:Panel ID="pnl_PageNew_UC" runat="server" Width="100%"> 
         123 
        </asp:Panel> 
        <asp:Panel ID="pnl_sign" runat="server" Width="100%" Visible="false"> 
         312 
        </asp:Panel> 
       </ContentTemplate> 
       <Triggers> 
        <asp:AsyncPostBackTrigger ControlID="rb_select_sign" EventName="SelectedIndexChanged" /> 
       </Triggers> 
      </asp:UpdatePanel> 
     </fieldset> 
    </div> 

在後面的代碼:

 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; 

      } 

      UpdatePanel1.Update(); 
     } 
相關問題