TemplateControl.Construct Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Performs design-time logic.
protected:
virtual void Construct();
protected virtual void Construct ();
abstract member Construct : unit -> unit
override this.Construct : unit -> unit
Protected Overridable Sub 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.
// 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
Remarks
The Construct method allows design-time code execution of the Page and UserControl controls.
Applies to
See also
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應