I have been answering questions on the SharePoint forums at MSDN Forums, and while some are really tricky and interesting, some are really basic beginner mistakes. A couple of questions lately have been about Web Part development and how to and where to create your controls. Most of these is easily solved if you understand how the Web Part event model works.
First of all you need basic ASP.NET understanding and know how the Page and Control objects work together, how a postback works etc. But I have even seen somewhat experienced ASP.NET developers failing at this point, probably due to the fact that Visual Studio have a slick interface for editing user controls and ASP.NET pages. When it comes to SharePoint you have no visual aids and you are out on thin water, and this knowledge is crucial.
SharePoint Web Part - Event Flow chart
To help new (or experienced) SharePoint Web Part developers out I created a chart that shows you how the different events flows from the Page, through the WebPartManager and WebPartZones, to the Web Part.
You can either click on the image above, to get it as a JPEG image, or download it as a printable PDF or XPS file.
Note: The Event Flow chart does not cover all events in the ASP.NET/SharePoint Page model, I have focused on the WebPart side.
There are five segments in the chart, from left to right;
- Page - events/methods happening in the Page (System.Web.UI.Page derivatives)
- WebPartManager - events/methods in the SPWebPartManager (inherited from WebPartManager)
- WebPartZone - the WebPartZone does not do really much in this scenario but rendering the WebParts.
- WebPart - the events happening during a normal view of a WebPart
- WebPart Postback - the event flow is a little bit different than the normal WebPart flow. Note that CreateChildControls is before the OnLoad and connections.
The chart contains a few white notations; these are not actual events/methods but contains information on what is happening at that point.
If you have any suggestions or comments about the flow, please feel free to contact me or post a comment. I’ll gladly keep the chart up to date.