从第二个UpdatePanel更新一个UpdatePanel

时间:2013-05-13 15:11:58

标签: c# asp.net ajax user-controls

这是一种已知行为吗?如果它是如何使它工作?

  • 我有2个更新面板。每个人都有一个DropDownList控件 它

  • 我有一个设置(绑定)第一个DropDownList的按钮。这个 作品。

  • 当我更改第一个DropDownList时,它应该更新第二个 DropDownList的。

  • 出于某种原因,第二个下拉列表永远不会更新。

这是伪代码:

第一更新面板& 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();
    }

帮我解决这个问题。

2 个答案:

答案 0 :(得分: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>

答案 1 :(得分:0)

这称为级联下拉列表,它有一个已知的技术,以及ASP.Net Ajax提供的控件......

http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/CascadingDropDown/CascadingDropDown.aspx