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.
Filed under: Software Development , Sharepoint, WebParts
[...] far as web part life cycle events go, things follow the normal web part life cycle model (see this post), however, the call to SetConnectionInterface() follows OnLoad(). This call connects the 2 web [...]
[...] by platinumdogs on January 14, 2009 I’ve updated my post on Sharepoint WebPart Lifecycle events, since the previous version wasn’t that [...]
Thanks for this post. It has helped me greatly.
I am having a problem when developing a MOSS webpart where am adding a LinkButton in GridView. The LinkButtons will be clicked by the user to download files.
1) The GridView is getting created in CreateChildControls(). Also the event handlers like OnRowCommand are mapped here.
2) The GridView is getting populated in OnPreRender(). This is because I only have the ConnectionConsumer value at this level from which I am creating the collection to assign as datasource. So the LinkButtons within the GridView get to be created at this level.
3) When the LinkButtons are clicked they don’t fire the OnRowCommand event. Whereas Sort/Page fires the OnRowCommand.
Since the LinkButtons are created only at the OnPreRender level, they are not getting mapped to the parent GridView’s OnRowCommand event.
When I moved the populating code up in CreateChildControls (using a fixed value for Connection data) the LinkButtons are firing OnRowCommand!
Any help?
[...] source: http://platinumdogs.wordpress.com/2008/10/14/sharepoint-webpart-lifecycle-events/ [...]
thanks for this article..
i have post it on my blog:
http://www.myrocode.com/post.aspx?id=93c3fc3f-4f28-4363-a4f3-1b5bae95fd65
No problem
thanks!
Your welcome