0

Is this a known behavior? and if it is how do I make it work?

  • I have 2 update panels. Each one has a DropDownList control inside of it.

  • I have 1 button that sets-up (binds) the first DropDownList. This works.

  • When I change the 1st DropDownList, it should update the 2nd DropDownList.

  • For some reason, the 2nd dropdown list never gets updated.

Here is the pseudo--code:

1st Update Panel & 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>

Code Behind:

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

Help me figure this one out.

Simcha Khabinsky
  • 1,970
  • 2
  • 19
  • 34

2 Answers2

1

You can merge them all in one updatepanel, dont forget btnSet.OnClick event

<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>
Emre
  • 563
  • 6
  • 18
0

This is called cascading dropdown lists, and there's a known technique for it, and a control provided by ASP.Net Ajax...

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

Jasmine
  • 4,003
  • 2
  • 29
  • 39