Export (0) Print
Expand All

Control.Init Event

Occurs when the server control is initialized, which is the first step in the its lifecycle.

[Visual Basic]
Public Event Init As EventHandler
[C#]
public event EventHandler Init;
[C++]
public: __event EventHandler* Init;

[JScript] In JScript, you can handle the events defined by a class, but you cannot define your own.

Event Data

The event handler receives an argument of type EventArgs.

Remarks

Server controls should perform any initialization steps that are required to create and set up an instance. You cannot use view-state information within this event; it is not populated yet. You should not access another server control during this event, regardless of whether it is a child or parent to this control. Other server controls are not certain to be created and ready for access.

Example

[Visual Basic, C#, C++] The following example assigns a custom event handler, Control_Init, to the Init event of a control, myControl, when the Page_Init method is called on the page that contains the control.

[Visual Basic] 
Sub Page_Init(sender As Object, e As EventArgs)
   ' Add a event Handler for 'Init'.
   AddHandler myControl.Init, AddressOf Control_Init
End Sub

Sub Control_Init(sender As Object, e As EventArgs)
   Response.Write(("The ID of the object initially : " + myControl.ID))
   ' Change the ID property.
   myControl.ID = "TestControl"
   Response.Write(("<br>The changed ID : " + myControl.ID))
End Sub

[C#] 
void Page_Init(object sender,EventArgs e)
{
   // Add a event Handler for 'Init'.
   myControl.Init += new System.EventHandler(Control_Init);
}

void Control_Init(object sender,EventArgs e)
{ 
  Response.Write("The ID of the object initially : " + myControl.ID);      
  // Change the ID property.
   myControl.ID="TestControl";
   Response.Write("<br>The changed ID : " + myControl.ID);
}

[C++] 

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 2000, Windows XP Professional, Windows Server 2003 family

See Also

Control Class | Control Members | System.Web.UI Namespace | Control Execution Lifecycle | Web Forms Page Processing

Show:
© 2014 Microsoft