- Interaction and life cycle is controlled by a Web Part Manager
- SPWebPartManager serializes and deserializes web part instances to content database
- Web parts are rendered with Chrome
- Title bar
- Rendered by the web part framework
- Rendered only when web part exists with web part zone. So if you take a web part and put it directly on a page, the chrome is not gonna render.
- Chrome is responsible for providing common look and feel to all web parts in an application
- Developers do not need to write code for these visual elements
Simplified Web Part Life Cycle
- OnInit: control initialization
- OnLoad: occurs when the control is loaded by the page object
- CreateChildControls: creates any child controls contained by the control
- EnsureChildControls: ensures that CreateChildControls is complete. (e.g. if you have code somewhere in the web part which is going to reference a property of a control that is created in the CreateChildControls, depending on when you're doing that, CreateChildControls may not have finished running yet. And EnsureChildControls simply blocks your execution until CreateChildControls is completed. And it guarantees that you're not going to try to reference anything that doesn't exist.)
- OnPreRender: perform any tasks that are going to change the state of any controls within the web part. (e.g. do binding to a gridview here, don't do it in CreateChildControls, because the viewstate may not be wired up yet and the control may not be in a valid state.)
- RenderContents: render the contents inside the chrome. Write code here to control the layout of the elements inside the chrome.
ASP.NET Web Parts vs SharePoint Web Parts
- In general, you should design new Web Parts that inherit from the ASP.NET 2.0 WebPart class.
- ASP.NET Web Parts have description file names that use the .webpart extension.
- ASP.NET Web Parts need to override RenderContents method.
- Windows SharePoint Services 3.0 Web Parts provide backward compatibility with Windows SharePoint Services 2.0.
- SharePoint Web Parts have description file names that use the .dwp extension.
- Following is a list of the added features of SharePoint Web Parts.
- Cross-page connections in SharePoint sites
- Connections between Web Parts that are outside of a Web Part zone
- Client-side connections using the Web Part Page Services Component
- Web Part data caching
- Asynchronous processing using Web Part work items