Sharepoint WebPart Lifecycle Events

Thursday, 23 April 2009 11:06 by myro

The original post can be found at platinumdogs.wordpress.com. 
Visit this arcticle at CodeProject if you need a deeper introduction to SharePoint Web Part's lifecycle events.

This post describes the lifecycle events of a Sharepoint Connectable WebPart wih a single ViewState backed property;

On Page Load

  • Constructor
  • OnInit
  • OnLoad
  • ConnectionConsumer method is called if web part is connectable (sets the connection providers interface in the webpart)
  • CreateChildControls
  • OnPreRender (if your web part is connectable you would typically call the connection provider here to retrieve data)
  • SaveViewState
  • Render
  • RenderChildren
  • RenderContents

On 1st Postback

  • (PostBack click handler sets ViewState via public Property)
  • Constructor
  • OnInit
  • CreateChildControls
  • OnLoad
  • PostBack click handling
  • ConnectionConsumer method is called if web part is connectable (sets the connection providers interface in the webpart)
  • OnPreRender (if your web part is connectable you would typically call the connection provider here to retrieve data)
  • SaveViewState
  • Render
  • RenderChildren
  • RenderContents

On 2nd Postback

(PostBack click handler sets ViewState via public Property)

  • Constructor
  • OnInit
  • LoadViewState
  • CreateChildControls
  • OnLoad
  • PostBack click handling
  • ConnectionConsumer method is called if web part is connectable (sets the connection providers interface in the webpart)
  • OnPreRender (if your web part is connectable you would typically call the connection provider here to retrieve data)
  • SaveViewState
  • Render
  • RenderChildren
  • RenderContents


Note that during the 2nd postback, LoadViewState, is called, since in the 1st postback the click handler sets the value of the ViewState backed public property. 
Credits for this post goes to Phil Harding. Thanks Phil for sharing. 

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags:  
Categories:   SharePoint 2007
Actions:   Bookmark and Share | Permalink | Comments (1) | Comment RSSRSS comment feed
If you consider this post usefull for your purposes, please consider visiting my sponsors to help me out with the myrocode.com maintenance. Thank you.

Comments