Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

TemplateControl.Construct Method

Performs construction time logic.

[Visual Basic]
Protected Overridable Sub Construct()
[C#]
protected virtual void Construct();
[C++]
protected: virtual void Construct();
[JScript]
protected function Construct();

Remarks

This method allows Page and UserControl authors to execute code at construction time without having to write a true constructor.

Example

[Visual Basic] 
' Create an event for this user control and
' name it myControl.
Public Event myControl As System.EventHandler


' Override the default constructor.
Protected Overrides Sub Construct()
   ' Specify the handler, MyInit, to be called when the myControl event
   ' is raised by the OnInit method.
   AddHandler Me.myControl, AddressOf MyInit
End Sub 'Construct


Protected Overrides Sub OnInit(e As EventArgs)
   RaiseEvent myControl(Me, e)
   Response.Write("The OnInit() method is used to raise the Init event.")
End Sub 'OnInit


' Use the MyInit handler to set the Message property value
' when this method is called.
Sub MyInit(sender As Object, e As System.EventArgs)
   _message = "Hello World!"
End Sub 'MyInit


[C#] 
// Create an event for this user control and
// name it myControl.
public event System.EventHandler myControl;

// Override the default constructor.
protected override void Construct()
{
   // Specify the handler, MyInit, to be called when the myControl event
   // is raised by the OnInit method.
   this.myControl += new System.EventHandler(MyInit);    
}

protected override void OnInit( EventArgs e)
{
   myControl(this ,e);
   Response.Write("The OnInit() method is used to raise the Init event.");
}

// Use the MyInit handler to set the Message property value
// when this method is called.
void MyInit(object sender,System.EventArgs e)
{
   _message = "Hello World!";
}

[C++] 
// Create an event for this user control and
// name it myControl.
public:
__event System::EventHandler* myControl;

// Override the default constructor.
protected:
void Construct()
{
   // Specify the handler, MyInit, to be called when the myControl event
   // is raised by the OnInit method.
   this->myControl += new System::EventHandler(this, &MyControl::MyInit);    
}

void OnInit( EventArgs* e)
{
   myControl(this ,e);
   Response->Write(S"The OnInit() method is used to raise the Init event.");
}

// Use the MyInit handler to set the Message property value
// when this method is called.
void MyInit(Object* sender,System::EventArgs* e)
{
   _message = S"Hello World!";
}

[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

TemplateControl Class | TemplateControl Members | System.Web.UI Namespace

Show:
© 2015 Microsoft