TemplateInstance 列挙体
アセンブリ: System.Web (system.web.dll 内)

Public Enumeration TemplateInstance


TemplateInstance 列挙体は、テンプレートのインスタンスを作成できる回数を示す値を指定します。TemplateInstance 列挙体の値は、TemplateInstanceAttribute クラスによって使用されます。特に、Single フィールドと Multiple フィールドは、それぞれ、テンプレートを 1 回または複数回インスタンス化できることを示します。1 回のみのテンプレート インスタンスの場合、そのテンプレート内のコントロールを参照できます。
プロパティ メタデータで Single 値を使用するコントロールには、CatalogZone コントロールの ZoneTemplate プロパティ、EditorZone コントロールの ZoneTemplate プロパティ、および WebPartZone コントロールの ZoneTemplate プロパティなどがあります。

TemplateInstance 列挙体と TemplateInstanceAttribute クラスの使用方法を次のコード例に示します。MyLoginView という名前のカスタム LoginView コントロールが AnonymousTemplate プロパティをオーバーライドして、TemplateInstanceAttribute クラスにより、AnonymousTemplate プロパティを 1 回のみインスタンス生成することを指定しています。
Imports Microsoft.VisualBasic Imports System Imports System.Data Imports System.ComponentModel Imports System.Web Imports System.Web.UI Imports System.Web.UI.WebControls Namespace Samples.AspNet.VB.Controls Public Class MyLoginView Inherits LoginView Private _anonymoustemplate As ITemplate <Browsable(False), DefaultValue(""), PersistenceMode(PersistenceMode.InnerProperty), TemplateContainer(GetType(LoginView)), TemplateInstance(TemplateInstance.Single)> _ Public Overrides Property AnonymousTemplate() As System.Web.UI.ITemplate Get Return _anonymoustemplate End Get Set(ByVal value As System.Web.UI.ITemplate) _anonymoustemplate = value End Set End Property End Class End Namespace
using System; using System.Data; using System.ComponentModel; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace Samples.AspNet.CS.Controls { public class MyLoginView : LoginView { private ITemplate _anonymoustemplate; [Browsable(false), DefaultValue(null), PersistenceMode(PersistenceMode.InnerProperty), TemplateContainer(typeof(LoginView)), TemplateInstance(TemplateInstance.Single) ] public override ITemplate AnonymousTemplate { get { return _anonymoustemplate; } set { _anonymoustemplate = value; } } } }
MyLoginView コントロールを使用する ASPX ファイルと、AnonymousTemplate プロパティ内の Label コントロールにアクセスする方法を次のコード例に示します。
<%@ Page Language="VB" %> <%@ Register TagPrefix="AspNetSamples" Namespace="Samples.AspNet.VB.Controls" Assembly="Samples.AspNet.VB.Controls" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Me.DataBind() Me.LoginViewLabel1.Text = "LoginView Anonymous Template Label Set Dynamically." End Sub </script> <html > <head runat="server"> <title>TemplateInstance Example</title> </head> <body> <form id="form1" runat="server"> <div> <AspNetSamples:MyLoginView id="MyLoginView1" runat="server"> <AnonymousTemplate> <asp:Label ID="LoginViewLabel1" runat="server" Text="Test"/> </AnonymousTemplate> </AspNetSamples:MyLoginView> </div> </form> </body> </html>
<%@ Page Language="C#" %> <%@ Register TagPrefix="AspNetSamples" Namespace="Samples.AspNet.CS.Controls" Assembly="Samples.AspNet.CS.Controls" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> protected void Page_Load(object sender, EventArgs e) { this.DataBind(); this.LoginViewLabel1.Text = "LoginView Anonymous Template Label Set Dynamically."; } </script> <html > <head runat="server"> <title>TemplateInstance Example</title> </head> <body> <form id="form1" runat="server"> <div> <AspNetSamples:MyLoginView id="MyLoginView1" runat="server"> <AnonymousTemplate> <asp:Label ID="LoginViewLabel1" runat="server" Text="Test"/> </AnonymousTemplate> </AspNetSamples:MyLoginView> </div> </form> </body> </html>

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- TemplateInstance 列挙体のページへのリンク