TemplateInstance 列挙型

定義

テンプレートのインスタンスを作成できる回数を指定します。

public enum class TemplateInstance
public enum TemplateInstance
type TemplateInstance = 
Public Enum TemplateInstance
継承
TemplateInstance

フィールド

Multiple 0

複数回インスタンス化されるテンプレート。

Single 1

1 回だけインスタンス化されるテンプレート。

次のコード例では、 列挙型と クラスを使用する TemplateInstance 方法を TemplateInstanceAttribute 示します。 という名前のカスタム LoginView コントロールは、 プロパティをAnonymousTemplateオーバーライドし、 クラスをTemplateInstanceAttribute使用して、プロパティのAnonymousTemplateインスタンスを 1 つだけ作成するように指定MyLoginViewします。

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;
            }
        }
    }
}
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

次のコード例は、 コントロールを使用MyLoginViewし、 プロパティ内AnonymousTemplateにあるコントロールにアクセスする方法をLabel示す ASPX ファイルです。

<%@ 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 xmlns="http://www.w3.org/1999/xhtml" >
<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="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 xmlns="http://www.w3.org/1999/xhtml" >
<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>

注釈

列挙は TemplateInstance 、テンプレートのインスタンスを作成できる回数を示す値を指定します。 クラスは TemplateInstanceAttribute 列挙体の値を TemplateInstanceAttribute 使用します。 特に、 Single フィールドと Multiple フィールドは、それぞれテンプレートの単一インスタンスと複数のインスタンスを指定します。 テンプレートの 1 つのインスタンスを使用すると、テンプレート内に含まれるコントロールを参照できます。

プロパティ メタデータで Single 値を使用するコントロールの例としてはZoneTemplate、コントロールの プロパティ、ZoneTemplateコントロールの CatalogZoneEditorZone プロパティ、および ZoneTemplate の プロパティがありますWebPartZone

適用対象

こちらもご覧ください