Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 436
Mathematics Avatar asked May 08 '13 11:05

Mathematics


3 Answers

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.

like image 91
Neeraj Dubey Avatar answered Nov 11 '22 12:11

Neeraj Dubey


I had the same issue. My problem was that the values of my ListItems were all the same :D

<asp:DropDownList ID="ddlFilterLogins" runat="server" Visible="true" AutoPostBack="true">
    <asp:ListItem Value="0" Text="All"></asp:ListItem>
    <asp:ListItem Value="0" Text="Some"></asp:ListItem>
    <asp:ListItem Value="0" Text="Some more"></asp:ListItem>
</asp:DropDownList>

It should be like this:

<asp:DropDownList ID="ddlFilterLogins" runat="server" Visible="true" AutoPostBack="true">
    <asp:ListItem Value="0" Text="All"></asp:ListItem>
    <asp:ListItem Value="1" Text="Some"></asp:ListItem>
    <asp:ListItem Value="2" Text="Some more"></asp:ListItem>
</asp:DropDownList>

Hope this helps. This might be hard to find sometimes :)

like image 37
Jeremiah Flaga Avatar answered Nov 11 '22 11:11

Jeremiah Flaga


Please, when you initialize it in Page_Load() check if not is postback. If you don't do it, you will always set the default value, and this replaces the value setted in the event.

if(!IsPostBack)
{
//DropDownList configuration
}
like image 1
Alberto León Avatar answered Nov 11 '22 13:11

Alberto León