2013-05-13 87 views
0

這是已知的行爲嗎?如果它是我如何使它工作?從第二UpdatePanel更新一個UpdatePanel

  • 我有2個更新面板。每個人都有一個DropDownList控件,它在 之內。

  • 我有1個按鈕,設置(綁定)第一個DropDownList。這 工程。

  • 當我更改第1個DropDownList時,它應該更新第2個 DropDownList。

  • 出於某種原因,第二個下拉列表永遠不會更新。

這裏是僞 - 代碼:

1日更新面板&的DropDownList:

<asp:Button ID="btnSet" runat="server"></asp:Button> 

<asp:UpdatePanel ID="UpdatePanel1" runat="server"> 
       <ContentTemplate> 
        <asp:DropDownList ID="DropDownList1" runat="server" 
         onselectedindexchanged="DropDownList1_SelectedIndexChanged" AutoPostBack="true"></asp:DropDownList> 
       </ContentTemplate> 
        <Triggers> 
         <asp:AsyncPostBackTrigger ControlID="btnSet" EventName="Click" /> 
        </Triggers> 
      </asp:UpdatePanel> 

<asp:UpdatePanel ID="UpdatePanel2" runat="server"> 
        <ContentTemplate> 
         <asp:DropDownList ID="DropDownList2" runat="server"></asp:DropDownList> 
        </ContentTemplate> 
         <Triggers> 
          <asp:AsyncPostBackTrigger ControlID="DropDownList1" EventName="SelectedIndexChanged" /> 
         </Triggers> 
       </asp:UpdatePanel> 

代碼背後:

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) 
    { 
     BindSecondDropDownList(); 
    } 

幫助我這一個。

回答

1

可以合併他們都在一個UpdatePanel中,不忘記btnSet.OnClick事件

<asp:UpdatePanel ID="UpdatePanel1" runat="server"> 
    <ContentTemplate> 
     <asp:Button ID="btnSet" runat="server"></asp:Button> 
     <asp:DropDownList ID="DropDownList1" runat="server" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" 
      AutoPostBack="true"> 
     </asp:DropDownList> 
     <asp:DropDownList ID="DropDownList2" runat="server"> 
     </asp:DropDownList> 
    </ContentTemplate> 
</asp:UpdatePanel> 
+0

這就是我最後要做的。 – 2013-05-14 20:30:41

+0

有一點幫助,將不勝感激。謝謝。 http://stackoverflow.com/questions/30352866/how-to-prevent-full-page-postback-on-selectedindexchange-for-dropdownlist – SearchForKnowledge 2015-05-20 15:07:31