TemplateInstance 열거형

정의

템플릿의 인스턴스를 만들 수 있는 횟수를 지정합니다.

public enum class TemplateInstance
public enum TemplateInstance
type TemplateInstance = 
Public Enum TemplateInstance
상속
TemplateInstance

필드

Multiple 0

여러 번 인스턴스화되는 템플릿입니다.

Single 1

한 번만 인스턴스화되는 템플릿입니다.

예제

다음 코드 예제를 사용 하는 방법에 설명 합니다 TemplateInstance 열거 및 TemplateInstanceAttribute 클래스입니다. 사용자 지정 LoginView 라는 컨트롤 MyLoginView, 재정의 AnonymousTemplate 사용 하 여 속성을 TemplateInstanceAttribute 클래스의 인스턴스를 하나만 지정할 수는 AnonymousTemplate 속성이 만들어집니다.

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

다음 코드 예제를 사용 하는 ASPX 파일은는 MyLoginView 제어 하 고 액세스 하는 방법을 보여 줍니다를 Label 내에 있는 컨트롤은 AnonymousTemplate 속성.

<%@ 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 열거형입니다. 특히 합니다 SingleMultiple 필드 단일 및 템플릿의 여러 인스턴스 각각 지정 합니다. 서식 파일의 단일 인스턴스를 사용 하면 템플릿 내에서 포함 된 컨트롤을 참조할 수 있습니다.

속성 메타 데이터에는 단일 값을 사용 하는 컨트롤의 예로 ZoneTemplate 의 속성을 CatalogZone 컨트롤을 ZoneTemplate 의 속성을 EditorZone 컨트롤 및 ZoneTemplate 속성은 WebPartZone.

적용 대상

추가 정보