Monday, June 9, 2014

Web parts in Sharepoint 2010 life cycle

OnInit: This method handles initialization of the control.

protected override void OnInit(EventArgs e)
{

}

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

protected override void OnLoad(EventArgs e)
{
}

CreateChildControls: This is the most popular event in web part life cycle. This creates any child controls. So if you are adding any control to display then you have to write in this method.

If it is Postback, It is called before OnLoad event.

protected override void CreateChildControls()
{
}


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.

Render

1.HTML Output is generated.
2.Event creates the HTML that appears in the body of the Web Part.

3. The CreateChildControls method is used to add controls to the WebPart, and the RenderContents method is used to tell the page framework how to render the control into HTML to display on a page.

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: This is executed when the web part is unloaded.
protected override void OnUnload(EventArgs e)
{
}


Creating Standard Toolbox Properties


Checkboxes

[WebBrowsable(true),
Category("Miscellaneous"),
Personalizable(PersonalizationScope.Shared),
WebDisplayName("Checkbox Option Text")]
public bool CustomCheckboxProp { get; set; }

Dropdown Lists

public enum ddlEnum { option1, option2, option3 }
[WebBrowsable(true),
Category("Miscellaneous"),
Personalizable(PersonalizationScope.Shared),
WebDisplayName("Dropdown List Display Text")]
public ddlEnum ddlProp { get; set; }


No comments:

Post a Comment