Search code examples
c#webformsupdatepanel

Drop Down List Selected Index changed not working in Update panel


I have a drop down list in UpdatePanel_2, it gets populated when Button_1 is clicked in UpdatePanel_1.

My ddlist markup is,

<asp:DropDownList id="drop1" runat="server"  EnableViewState="true" AutoPostBack="true" OnSelectedIndexChanged="Drop1_SelectedIndexChanged" />

then code behind is,

 protected void Drop1_SelectedIndexChanged(object sender, EventArgs e)
        { }

I also tried putting AutoPostback=true to my DropDownList, still no success.

I also added triggre to update panel 2 but no gain,

       <Triggers>
    <asp:AsyncPostbackTrigger ControlID="drop1" EventName="SelectedIndexChanged" />
</Triggers>

I am populating DropDownList using a button not PAGE LOAD METHOD PLEASE READ before answering. Thanks


Solution

  • Check the data to populate the DropDownList in the Page_Load event and always check IspostBack:

    if(!IsPostBack)
    {
     //DropDownList configuration
    }
    

    Use EnableViewState:

     <asp:DropDownList ID="ddlAddDepPlans" runat="server" AutoPostBack="true" EnableViewState="true" />
    

    Hope it helps you.