Construct Method
.NET Framework Class Library
TemplateControl..::.Construct Method

Performs design-time logic.

Namespace:  System.Web.UI
Assembly:  System.Web (in System.Web.dll)
Visual Basic (Declaration)
Protected Overridable Sub Construct
Visual Basic (Usage)
Me.Construct()
C#
protected virtual void Construct()
Visual C++
protected:
virtual void Construct()
JScript
protected function Construct()

The Construct method allows design-time code execution of the Page and UserControl controls.

The following code example demonstrates how to override the Construct method of a custom control that is derived from the TemplateControl class.

For the full definition of the MyControl class, see TemplateControl.

Visual Basic
' Create an event for this user control
Public Event myControl As System.EventHandler

' Override the default constructor.
Protected Overrides Sub Construct()
    ' Specify the handler for the OnInit method.
    AddHandler Me.myControl, AddressOf MyInit
End Sub

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


' Use the MyInit handler to set the Message property
Sub MyInit(ByVal sender As Object, ByVal e As System.EventArgs)
    Message = "Hello World!"
End Sub


C#
// Create an event for this user control
public event System.EventHandler myControl;

// Override the default constructor.
protected override void Construct()
{
    // Specify the handler for the OnInit method.
    this.myControl += new 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
void MyInit(object sender, System.EventArgs e)
{
    Message = "Hello World!";
}

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
Page view tracker