Drop Down List Selected Index changed not working in Update panel

岁酱吖の 提交于 2019-12-12 07:35:45

问题


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


回答1:


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.




回答2:


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




回答3:


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
}



回答4:


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




回答5:


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>


来源:https://stackoverflow.com/questions/16439037/drop-down-list-selected-index-changed-not-working-in-update-panel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!