This documentation is archived and is not being maintained.
TemplateControl.Construct Method
.NET Framework 1.1
Performs construction time logic.
[Visual Basic] Protected Overridable Sub Construct() [C#] protected virtual void Construct(); [C++] protected: virtual void Construct(); [JScript] protected function Construct();
Remarks
This method allows Page and UserControl authors to execute code at construction time without having to write a true constructor.
Example
[Visual Basic] ' Create an event for this user control and ' name it myControl. Public Event myControl As System.EventHandler ' Override the default constructor. Protected Overrides Sub Construct() ' Specify the handler, MyInit, to be called when the myControl event ' is raised by the OnInit method. AddHandler Me.myControl, AddressOf MyInit End Sub 'Construct Protected Overrides Sub OnInit(e As EventArgs) RaiseEvent myControl(Me, e) Response.Write("The OnInit() method is used to raise the Init event.") End Sub 'OnInit ' Use the MyInit handler to set the Message property value ' when this method is called. Sub MyInit(sender As Object, e As System.EventArgs) _message = "Hello World!" End Sub 'MyInit [C#] // Create an event for this user control and // name it myControl. public event System.EventHandler myControl; // Override the default constructor. protected override void Construct() { // Specify the handler, MyInit, to be called when the myControl event // is raised by the OnInit method. this.myControl += new System.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 value // when this method is called. void MyInit(object sender,System.EventArgs e) { _message = "Hello World!"; } [C++] // Create an event for this user control and // name it myControl. public: __event System::EventHandler* myControl; // Override the default constructor. protected: void Construct() { // Specify the handler, MyInit, to be called when the myControl event // is raised by the OnInit method. this->myControl += new System::EventHandler(this, &MyControl::MyInit); } void OnInit( EventArgs* e) { myControl(this ,e); Response->Write(S"The OnInit() method is used to raise the Init event."); } // Use the MyInit handler to set the Message property value // when this method is called. void MyInit(Object* sender,System::EventArgs* e) { _message = S"Hello World!"; }
[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Platforms: Windows 2000, Windows XP Professional, Windows Server 2003 family
See Also
TemplateControl Class | TemplateControl Members | System.Web.UI Namespace
Show: