TemplateControl クラス

Page クラスと UserControl クラスに、基本の機能セットを提供します。

この型のすべてのメンバの一覧については、TemplateControl メンバ を参照してください。

System.Object
   System.Web.UI.Control
      System.Web.UI.TemplateControl
         System.Web.UI.Page
         System.Web.UI.UserControl

MustInherit Public Class TemplateControl
   Inherits Control
   Implements INamingContainer
[C#]
public abstract class TemplateControl : Control, INamingContainer
[C++]
public __gc __abstract class TemplateControl : public Control,
   INamingContainer
[JScript]
public abstract class TemplateControl extends Control implements
   INamingContainer

スレッドセーフ

この型の public static (Visual Basicでは Shared) のすべてのメンバは、マルチスレッド操作で安全に使用できます。インスタンスのメンバの場合は、スレッドセーフであるとは限りません。

使用例

 
' Create a code-behind custom UserControl class (the UserControl class 
' is derived from TemplateControl), named MyControl, that
' overrides the Construct method of the TemplateControl class.
' When the control is initialized, the overridden Construct method
' is called, which allows the custom initialization logic
' to be called as well.
Imports System
Imports System.Web.UI
Imports System.Web.UI.WebControls

' The custom user control class.
 Public Class MyControl
   Inherits UserControl
   ' Create a Message property and accessors.
   Private _message As String = Nothing
   
   Public Property Message() As String
      Get
         Return _message
      End Get
      Set
         _message = value
      End Set
   End Property
   
   ' 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
   
   ' Write the value of the Message property when the control
   ' is rendered.
   Protected Overrides Sub Render(output As HtmlTextWriter)
      output.Write(("<br>Message :" & _message))
   End Sub 'Render
 End Class 'MyControl

[C#] 
// Create a code-behind custom UserControl class (the UserControl class 
// is derived from TemplateControl), named MyControl, that
// overrides the Construct method of the TemplateControl class.
// When the control is initialized, the overridden Construct method
// is called, which allows the custom initialization logic
// to be called as well.
using System;
using System.Web.UI;
using System.Web.UI.WebControls;



 // The custom user control class.
 public class MyControl:UserControl
 {
   // Create a Message property and accessors.
   private string _message = null;
   public string Message
   {
      get
      {
         return _message;
      }
      set
      {
         _message = value;
      }
   }

   // 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!";
   }

   // Write the value of the Message property when the control
   // is rendered.
   protected override void Render(HtmlTextWriter output) 
   {
      output.Write("<br>Message :" + _message);
   }
 }

[C++] 
// Create a code-behind custom UserControl class (the UserControl class 
// is derived from TemplateControl), named MyControl, that
// overrides the Construct method of the TemplateControl class.
// When the control is initialized, the overridden Construct method
// is called, which allows the custom initialization logic
// to be called as well.
#using <mscorlib.dll>
#using <System.Web.dll>
#using <System.dll>
using namespace System;
using namespace System::Web::UI;
using namespace System::Web::UI::WebControls;



// The custom user control class.
public __gc class MyControl:public UserControl
{
   // Create a Message property and accessors.
private:
   String* _message;
public:
   __property String* get_Message()
   {
      return _message;
   }
   __property void set_Message( String* value )
   {
      _message = value;
   }

   // 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!";
   }

   // Write the value of the Message property when the control
   // is rendered.
   void Render(HtmlTextWriter* output) 
   {
      output->Write(S"<br>Message :{0}", _message);
   }
};

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

名前空間: System.Web.UI

プラットフォーム: Windows 2000, Windows XP Professional, Windows Server 2003 ファミリ

アセンブリ: System.Web (System.Web.dll 内)

参照

TemplateControl メンバ | System.Web.UI 名前空間