TemplateControl クラスとは? わかりやすく解説

TemplateControl クラス

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

名前空間: System.Web.UI
アセンブリ: System.Web (system.web.dll 内)
構文構文

Public MustInherit Class
 TemplateControl
    Inherits Control
    Implements INamingContainer, IFilterResolutionService
Dim instance As TemplateControl
public abstract class TemplateControl : Control,
 INamingContainer, IFilterResolutionService
public ref class TemplateControl abstract :
 public Control, INamingContainer, IFilterResolutionService
public abstract class TemplateControl extends
 Control implements INamingContainer, IFilterResolutionService
public abstract class TemplateControl extends
 Control implements INamingContainer, IFilterResolutionService
解説解説
使用例使用例

TemplateControl クラスから MyControl という名前のコントロール派生させ、Construct メソッドオーバーライドする方法次のコード例示しますMyControl初期化されると、オーバーライドされた Construct メソッド呼び出されます。

Imports System
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Security.Permissions

' The custom user control class.
<AspNetHostingPermission(SecurityAction.Demand, _
   Level:=AspNetHostingPermissionLevel.Minimal)> _
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
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Security.Permissions;


 // The custom user control class.
 [AspNetHostingPermission(SecurityAction.Demand, 
   Level=AspNetHostingPermissionLevel.Minimal)]
 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);
   }
 }
.NET Framework のセキュリティ.NET Frameworkセキュリティ
継承階層継承階層
System.Object
   System.Web.UI.Control
    System.Web.UI.TemplateControl
       System.Web.UI.Page
       System.Web.UI.UserControl
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「TemplateControl クラス」の関連用語

TemplateControl クラスのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



TemplateControl クラスのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS