Export (0) Print
Expand All

TemplateControl.Construct Method

Performs design-time logic.

Namespace:  System.Web.UI
Assembly:  System.Web (in System.Web.dll)

protected virtual void 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.

// 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!";
}

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

Show:
© 2014 Microsoft