Compartilhar via


TemplateControl.Construct Método

Definição

Executa a lógica de tempo de design.

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

Exemplos

O exemplo de código a seguir demonstra como substituir o Construct método de um controle personalizado derivado da TemplateControl classe.

Para obter a definição completa da MyControl classe, consulte 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

Comentários

O Construct método permite a execução de código em tempo de design dos controles e do Page tempo UserControl de design.

Aplica-se a

Confira também