I've got the following DropDownList in my code that is firing in the wrong order:
public class MyWebpart : WebPart
{
private DropDownList dropDown = new DropDownList();
private string selectedValue;
public Webpart()
{
}
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
dropDown.AutoPostBack = true;
dropDown.SelectedIndexChanged += new EventHandler(DropDown_SelectedIndexChanged);
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
this.EnsureChildControls();
}
protected void DropDown_SelectedIndexChanged(Object sender, EventArgs e)
{
selectedValue - dropDown.SelectedValue;
}
protected void override void CreateChildControls()
{
base.CreateChildControls();
// create some stuff here
}
I was expecting when the drop down selection changes, the DropDown_SelectedIndexChanged will get called first, but instead it went through the entire lifecycle going from OnInit, OnLoad, CreateChildControls, then DropDown_SelectedIndexChanged.
Am I missing something? How can I get DropDown_SelectedIndexChanged call first?