ASP.NET Page Lifecycle is very important piece of knowledge every ASP.NET developer must know, and unfortunately some of ASP.NET developer out there don’t know and they think it’s not important to know.
Let’s dig in and let’s examine ASP.NET Lifecycle but in short list and description:
- In this event all Controls created and Initialized with their default values. You can create dynamic Controls here. You can set theme programmatically here
- In this event you can read the Controls properties the were set in Design Mode and can not read values changed by user.
- This event fires only if the page is posted back “IsPostback == true;” and here View State data where are stored in hidden form fields get de-serialized and loads all controls View State data.
- This event only fires when Page is posted back and Controls which implement IPostBackDataHandler interface get loaded with values from HTTP POST data.
- This event is well known among ASP.NET developers and here Page gets loaded and after it all Load() events of Page Controls fired.
- Control Event Handlers:
- These are basically event handlers like Button click event handler “Button1_Click()” which fires after Page_Load() event.
- This event is fired for each page child controls and her you can change controls values.
- In this event Controls View State saved in Page hidden fields.
- Here all Controls get rendered or every Page Controls Render method is called.
- Here we can have Page and Controls clean up operations. This event the Page and its Controls are rendered.
- ASP.NET Lifecycle will be called ever time there a request for the page.
- HTTP POST data has only one value per control, that’s why Control like Textbox can gets value from HTTP Post but Control like DropDownList can not gets data from HTTP Post it can gets data from View State.
- Init() and Unload() events are fired from outside to inside controls, fro example: user control Init() event will be fired beforePage_Init() event