Saturday, May 11, 2013

Visual Web Part Life Cycle

SimpleVisualWebPart - OnInit

SimpleVisualWebPart - OnLoad

SimpleVisualWebPart - CreateChildControls

SimpleVisualWebPartUserControl - OnInit

SimpleVisualWebPartUserControl - OnLoad

SimpleVisualWebPartUserControl - Page_Load

SimpleVisualWebPart - OnPreRender

SimpleVisualWebPartUserControl - OnPreRender

SimpleVisualWebPart - SaveViewState

SimpleVisualWebPartUserControl - SaveViewState

SimpleVisualWebPart - Render

SimpleVisualWebPartUserControl - Render

SimpleVisualWebPart - RenderContents

SimpleVisualWebPartUserControl - OnUnload

SimpleVisualWebPartUserControl - Dispose

SimpleVisualWebPart - OnUnload

SimpleVisualWebPart - Dispose

Event Phase
Method or event to override
Initialize Initialize settings needed during the lifetime of the incoming Web request. Init event (OnInit method)
Load view state At the end of this phase, the ViewState property of a control is automatically populated. A control can override the default implementation of the LoadViewState method to customize state restoration. LoadViewState method
Load Perform actions common to all requests, such as setting up a database query. At this point, server controls in the tree are created and initialized, the state is restored, and form controls reflect client-side data. Load event
(OnLoad method)
Handle postback events Handle the client-side event that caused the postback and raise appropriate events on the server.

Note   Only controls that process postback events participate in this phase.
RaisePostBackEvent method
Prerender Perform any updates before the output is rendered. Any changes made to the state of the control in the prerender phase can be saved, while changes made in the rendering phase are lost. PreRender event
(OnPreRender method)
SaveViewState The ViewState property of a control is automatically persisted to a string object after this stage. This string object is sent to the client and back as a hidden variable. For improving efficiency, a control can override the SaveViewState method to modify the ViewState property. SaveViewState method
Render Generate output to be rendered to the client. Render method
Dispose Perform any final cleanup before the control is torn down. References to expensive resources such as database connections must be released in this phase. Dispose method
Unload Perform any final cleanup before the control is torn down. Control authors generally perform cleanup in Dispose and do not handle this event. UnLoad event (On UnLoad