Search code examples
asp.netdrop-down-menuviewstateautopostback

DropDownList in ASP.net pages has OnSelectedIndexChanged fire twice


html

    <asp:DropDownList ID="ddlOffice" runat="server" Rows="10" Width="300px" AutoPostBack="true" OnSelectedIndexChanged="ddlOffice_SelectedIndexChanged" EnableViewState="true"   />

Even though according to MSDN I am doing everything correctly. the SelectedIndexChanged still fires twice. Any ideas how this can fixed?


Solution

  • One possible reason: If you have a also registered the event handler in codebehind(f.e. via Handles clause in VB.NET or += in C#) it will cause the event to be fired twice.

    Then you just have to remove one of it, for example on aspx:

    <asp:DropDownList ID="ddlOffice" 
        runat="server" Rows="10" Width="300px"
        AutoPostBack="true" 
        EnableViewState="true"   />