简体   繁体   中英

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

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.

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 :)

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
}

You can use Init event instead of SelectIndexChanged. It worked fine for me. Hope you got my point.

It was also a wired problem for me. finally It was because of identical listitems in the dropdown as shown below. during development you may use same items just for testing. change them.

<asp:ListItem>Business</asp:ListItem>
<asp:ListItem>Business</asp:ListItem>
<asp:ListItem>Business</asp:ListItem>
<asp:ListItem>Business</asp:ListItem>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM