TemplateControl.Construct 方法

定义

执行设计时逻辑。

protected:
 virtual void Construct();
protected virtual void Construct ();
abstract member Construct : unit -> unit
override this.Construct : unit -> unit
Protected Overridable Sub Construct ()

示例

下面的代码示例演示如何重写 Construct 派生自 TemplateControl 类的自定义控件的方法。

有关类的完整定义 MyControl ,请参阅 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!";
}
 ' 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

注解

该方法 Construct 允许设计时代码执行 PageUserControl 控件。

适用于

另请参阅