Читати англійською Редагувати

Поділитися через


TemplateControl.Construct Method

Definition

Performs design-time logic.

C#
protected virtual void Construct();

Examples

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.

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

Remarks

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

Applies to

Продукт Версії
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

See also