TemplateControl.Construct 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
執行設計階段邏輯。
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 允許和 UserControl 控制項的設計階段程式碼執行 Page 。