2

When changing the value in dropdownlist. selectedIndexchange should call before PageLoad event.

How can I call dropdownlist selectedIndexchanged before PageLoad event?

Damon
  • 3,004
  • 7
  • 24
  • 28
AFofandi
  • 41
  • 1
  • 2
  • 7
  • 1
    IHMO, Firstly search more about your doubts you will get somewhere then fire a question. http://stackoverflow.com/questions/373885/handle-event-before-page-load Now, Before diving into asp, its better if you can understand the ASP.NET Page Life Cylce. – Nagaraj Tantri Dec 08 '13 at 13:32

1 Answers1

2

as per ASP.NET Life cycle Page_Load Event Fires first and then the other control events will be fired.

but you can fire the dropDownList SelectedIndexChanged event by calling SelectedIndexChanged event manually from Page_Load event handling code as a first step.

Try This:

protected void Page_Load(object sender, EventArgs e)
{
        //call the DropDownList1 selectedindexchanged event manually
        dropDownList1_SelectedIndexChanged(sender, e);

       //page load event handling code

}

protected void dropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
     //DropDownList1 SelectedIndexChanged event handling code.
}
Sudhakar Tillapudi
  • 25,935
  • 5
  • 37
  • 67
  • Make sure to pass `dropdownList1` instead of `sender` from the `Page_Load` to avoid potential casting error in the `dropDownList1_SelectedIndexChanged` event. – yazanpro May 13 '19 at 00:12