简体   繁体   中英

Drop down's OnSelectedIndexChanged event isn't firing when changed

I have search a lot, and tried all solutions I could find for this problem, but nothing works.

My OnSelectedIndexChanged event is never fired when selected item in the drop down list is changed.

From View:

<asp:DropDownList Name="selectYear" EnableViewState="True" CssClass="select" ID="ddlYear" AutoPostBack="True" runat="server" OnSelectedIndexChanged="ddlYear_SelectedIndexChanged"/>

My OnLoad method:

protected override void OnLoad(EventArgs e)
{
    base.OnLoad(e);
    SetText(); //Setting text on labels

    if(IsPostBack)
    {
         return;
    }
    InitDropDown();
    InitGrid();
}

I have tried both with and without the post-back-if-statement. None of them is working.

My event metode (this method is never fired, why?):

protected void ddlYear_SelectedIndexChanged(object sender, EventArgs e)
{
    if (OnTransactionYearChanged == null) return;
           OnTransactionYearChanged();
}

Does anyone know? It's part of a Web Forms applications.

You have

if(IsPostBack)
{
     return;
}

and your dropdownlist is not working properly during postbacks.

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