ASP.NET Drop-Down List OnSelectedIndexChanged not firing

When using an OnSelectedIndexChanged event on a drop down list in an ASP.NET page, the event code wasn’t getting executed.

<script>
Sub ClickEvent(ByVal sender As Object, ByVal e As System.EventArgs)
        'Called when the drop-down is changed
        Label1.text="Clicked"
End Sub
</script>
<asp:DropDownList ID="DropDown1" runat="server" OnSelectedIndexChanged="ClickEvent" >
  <asp:ListItem Text="X-ray" Selected="False" Value="1" />
  <asp:ListItem Text="Yankee" Selected="true"  Value="2" />
  <asp:ListItem Text="Zulu" Selected="false"  Value="3" />
</asp:DropDownList>
<asp:Label ID="Label1" runat="server" />

The solution was to add AutoPostback="True" to the DropDownList entry, for example
<asp:DropDownList ID="DropDown1" runat="server" OnSelectedIndexChanged="ClickEvent" AutoPostback="True">

Leave a Reply

Your email address will not be published. Required fields are marked *