WebPart.OnInit Method

The event handler for the System.Web.UI.Control.Init event that occurs as the Web Part is being instantiated.

Namespace:  Microsoft.SharePoint.WebPartPages
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: No

Syntax

'Declaration
Protected Overrides Sub OnInit ( _
    e As EventArgs _
)
'Usage
Dim e As EventArgs

Me.OnInit(e)
protected override void OnInit(
    EventArgs e
)

Parameters

Remarks

If there are any initialization steps to create and set up an instance of the Web Part, you can subscribe to the System.Web.UI.Control.Init event by adding an appropriate event handler MyInitHandler in the Web Part constructor. For example:

this.Init += new EventHandler (MyInitHandler);

At this stage in the Web Part life cycle, its view state has yet to be populated. Additionally, you cannot access other server controls when this method is called, regardless of whether it is a child or parent to this control, because you cannot be certain that other server controls are created and ready for access.

See Also

Reference

WebPart Class

WebPart Members

Microsoft.SharePoint.WebPartPages Namespace