Sharepoint WebPart 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.

Leave a Reply

Your email address will not be published. Required fields are marked *