Web Part Life Cycle in SharePoint 2010

Most of the SharePoint developer may know the life cycle of ASP.NET. While working with SharePoint, it may possible not aware with Web Part life cycle. I am trying to explain SharePoint 2010 Web Part life cycle in this post.

It is very much similar as ASP.NET page life cycle with enhancement of few events.

OnInit: This method handles initialization of the control.

OnLoad: This event handles the Load event and also used for initialize the control. But it is not intended for loading data or other processing functionality.

CreateChildControls: This creates any child controls.

EnsureChildControls: This method ensures that CreateChildControls has executed. EnsureChildControls method must be called to prevent null reference exceptions.

SaveViewState: View state of the web part saved.

OnPreRender: This method handles or initiates tasks such as data loading that must complete before the control can render.

Page.PreRenderComplete: The page fires the PreRenderComplete event after all controls have completed their OnPreRender methods.

Render: This method is used to render everything.

RenderContents: Renders the contents of the control only, inside of the outer tags and style properties.

OnUnload: Performs the final clean up.

I hope this will help to understand Web Part life cycle.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s