Saturday, August 30, 2014

ASP.NET Page Life Cycle

Init
This event happens in the ASP.NET page and can be used for:
Ø             Creating controls dynamically, in case you have controls to be created on runtime.
Ø             Any setting initialization.
Ø             Master pages and the settings.
Ø         In this section, we do not have access to viewstate, postedvalues and neither the controls are initialized.
Load
In this section, the ASP.NET controls are fully loaded and you write UI manipulation logic or any other logic over here.
Validate
If you have valuators on your page, you would like to check the same here.
Render
It’s now time to send the output to the browser. If you would like to make some changes to the final HTML which is going out to the browser, you can enter your HTML logic here.
Unload
Page object is unloaded from the memory.
                                                                                                                                          
Seq
Events
Controls Initialized
View state
Available
Form data
Available
What Logic can be written here?
1
Init
No
No
No
Note: You can access form data etc. by using ASP.NET request objects but not by Server controls.Creating controls dynamically, in case you   have controls to be   created on runtime. Any settinginitialization.Master pages and them settings. In this section, we do not have access to viewstate , posted values and neither the controls are initialized.
2
Load view state
Not guaranteed
Yes
Not guaranteed
You can access view state and any synch logic where you want viewstate to be pushed to behind code variables can be done here.
3
PostBackdata
Not guaranteed
Yes
Yes
You can access form data. Any logic where you want the form data to be pushed to behind code variables can be done here.
4
Load
Yes
Yes
Yes
This is the place where you will put any logic you want to operate on the controls. Like flourishing a combobox from the database, sorting data on a grid, etc. In this event, we get access to all controls,   viewstate and their posted values.
5
Validate
Yes
Yes
Yes
If your page has validators or you want to execute validation for your page, this is the right place to the same.
6
Event
Yes
Yes
Yes
If this is a post back by a button click or a dropdown change, then the relative events will be fired. Any kind of logic which is related to that event can be executed here.
7
Pre-render
Yes
Yes
Yes
If you want to make final changes to the UI objects like changing tree structure or property values, before these controls are saved in to view state.
8
Save view state
Yes
Yes
Yes
Once all changes to server controls are done, this event can be an opportunity to save control data in to view state.
9
Render
Yes
Yes
Yes
If you want to add some custom HTML to the output this is the place you can.
10
Unload
Yes
Yes
Yes
Any kind of clean up you would like to do here.

1 comment: