>

Below is the list of methods that are being called in the Web Part life cycle.

  • protected override void OnInit(EventArgs e)
  • protected override void OnLoad(EventArgs e)
  • protected override void CreateChildControls()
  • protected override void LoadViewState(object savedState)
  • protected override void OnPreRender(EventArgs e)
  • protected override void Render(System.Web.UI.HtmlTextWriter writer)
  • protected override void OnUnload(EventArgs e)
  • public override void Dispose()

– OnInit: Configuration values set using WebBrowsable properties and those in web part task pane are loaded into the web part

– OnLoad: User generated events life button trigger events are loaded into the scope of web part.

– CreateChildControls: All the controls specified are created and added to controls collection.

When the page is being rendered for the first time the method generally occurs after the OnLoad() event. In case of postback, it is called before the OnLoad() event. We can make use of EnsureChildControls() – It checks to see if the CreateChildControls method has yet been called, and if it has not, calls it

– LoadViewState: The view state of the web part is populated over here

– OnPreRender: Here we can change any of the web part properties before the control output is drawn

– Render: Html Output is generated.

– OnUnload: I think the memory assigned to perform all the above tasks are unloaded here

– Dispose: This will dispose the references of the web part from cache of server as the web part is completely loaded

NOTE:

– LoadViewState only occurs on postback.

– On a button click steps 1, 2, 3 and 4 will be processed before any onClick methods.


References:

http://msdn.microsoft.com/en-us/library/ms366536.aspx

Advertisements