Web Parts are server side code that runs within the context of the site page in SharePoint. There are many OOTB web parts that are available but one can create their own.
There mainly two types of web parts which are as follows:
- ASP.NET Web PartThese Web Parts are built on top of the ASP.NET Web Part infrastructure. The ASP.NET-style Web Parts have a dependency on System.Web.dll and must inherit from the WebPart base class in the System.Web.UI.WebControls.WebParts namespace. You can use these Web Parts in ASP.NET applications and in SharePoint Foundation, which makes them highly reusable.
- SharePoint Web PartThese Web Parts have a dependency on Microsoft.SharePoint.dll and must inherit from the WebPart base class in theMicrosoft.SharePoint.WebPartPages namespace. These Web Parts can only be used in SharePoint websites.
The custom web parts that are being created can be personalized by declaring properties that are visible to the user in the properties section. The custom properties are to be declared in the web part class and can be referenced in the user control. The settings to be provided for the custom properties are as follows:
- Category - sets under which section heading the custom property is to be displayed
- WebBrowsableAttribute - it makes sure that the property is visible when the web part properties are edited
- WebDescriptionAttribute - displays a description of the custom property as a tooltip
- WebDisplayNameAttribute - sets the name of the property
- PersonalizableAttribute - determines whether the changes made are affected for all the users or for a particular user. This can be set by changing the scope as "PersonalizationScope.Shared" or "PersonalizationScope.User".Shared scope indicates that the property normally only allows loading or saving of data associated with all users. Whereas when the property's control is running on a page in User scope, the property's per-user and all-user data will be loaded and merged. In this case, though, only per-user data will be saved when a page is running in User scope.
The web part page life cycle
Event Phase
|
Description
|
Method or event to override
|
OnInit | Configuration values set using WebBrowsable properties and those in web part task. | Init event (OnInit method) |
LoadViewState | The view state of the web part is populated over here. | LoadViewState method |
CreateChildControls OnLoad | All the specified controls are created and added to the controls collection. When the page is being rendered for the first time CreateChildControls occurs after the OnLoad event. In case of postback it is called before the OnLoad() event. We can make use of EnsureChildControls() – It checks to see if the CreateChildControls() has yet been called, and if it has not, calls it. Perform actions common to all requests, such as setting up a database query. At this point, server controls in the tree are created and initialized, the state is restored, and form controls reflect client-side data. | CreateChildControls method Load event (OnLoad method) |
User generated event | Handle the client-side event that caused the postback and raise appropriate events on the server. Note Only controls that process postback events participate in this phase. | RaisePostBackEvent method |
On PreRender | We can change any web part properties before the control output is drawn. | PreRender event (OnPreRender method) |
RenderContents | HTML output is generated to render the output. | Render method |
SaveViewState | ViewState of the web part is serialized and saved. | SaveViewState method |
Dispose | Perform any final cleanup before the control is torn down. References to expensive resources such as database connections must be released in this phase. | Dispose method |
Unload | Perform any final cleanup before the control is torn down. Control authors generally perform cleanup in Dispose and do not handle this event. | UnLoad event (On UnLoad) |
Styling of web part reference: http://msdn.microsoft.com/en-us/library/hh537935(v=office.14).aspx
No comments:
Post a Comment