I have a drop down list that appears throughout my site. For code re-usability purposes I made it a Server Control.
Everything was working great. However I would like to add a event handler for SelectedIndexChanged
This is not working for me:
this.OnSelectedIndexChanged = "CultureSelectorControl1_SelectedIndexChanged";
followed by:
protected void CultureSelectorControl1_SelectedIndexChanged(object sender, EventArgs e)
{
// code here
}
Please let me know what to change here. Thanks!
Looks like you are confusing the markup syntax for event hookups with the code equivalent. If you are subclassing DropDownList, then just use this code for handling the event internally:
Controls shouldn’t subscribe to their own events.
If you are using a user control instead which contains the DropDownList control and you want to handle the event in the user control, then you can either do it this way in code during Page_Init:
Or on the markup for the DropDownList: