Wednesday, 11 March 2015

ASP.NET Page Life Cycle Events
PreInit
Init
PreLoad
Load
Control Events
PreRender
SaveViewState
Render

Unload 
PreInit()
This is the first event which raised  in asp.net page lifecycle
Check for Request is for Post Back or not.
All dynamic control need to be created
Theme Change, Master Page Set at runtime
Init()
Raised after all controls have been initialized
Build up a tree of controls from the ASPX file
Turn on view state monitoring – any changes in control will be tracked by View State for future.
PreLoad()
Load view state data for page and controls
Load Postback data if needed
We can process any kind operation that need to perform before page load
Load()
OnLoad methods control called for each and every control
We can create the connection initialization for any kind of external source like database connection
We can also set the control properties
Control Events
If this is an postback request , Corresponding events will triggered. Like, if the post back is happing for button click, then Button_Click Event will fired.
PreRender
Each control of the page has a PreRender event which is being invoked.
EnsureChildControls is also being called during this events
DataBind method for all control has also been called
If we want to change any thing to any control this is the last event where we can do because after the pageRender starts 
SaveViewState
ViewState Monitoring is turned off as here all the ViewState Data need to be saved.
View State data saved in hidden filed called _VIEWSTATE
Render
Pages calls the Render method for each and every control.
Text writer that writes the output to the as output stream
Output steam set to the page's Response property.
Unload
This is the last event of asp.net page life cycle
This ensure the Request and Response has been set to null.
This is called only after the content of the page fully rendered and response sent to client

No comments:

Post a Comment