Share via


TagPrefixAttribute(String, String) 생성자

정의

TagPrefixAttribute 클래스의 새 인스턴스를 초기화합니다.

public:
 TagPrefixAttribute(System::String ^ namespaceName, System::String ^ tagPrefix);
public TagPrefixAttribute (string namespaceName, string tagPrefix);
new System.Web.UI.TagPrefixAttribute : string * string -> System.Web.UI.TagPrefixAttribute
Public Sub New (namespaceName As String, tagPrefix As String)

매개 변수

namespaceName
String

사용자 지정 컨트롤 네임스페이스를 식별하는 문자열입니다.

tagPrefix
String

사용자 지정 컨트롤 접두사를 식별하는 문자열입니다.

예외

namespaceName 또는 tagPrefixnull이거나 빈 문자열("")인 경우

예제

다음 코드 예제에서는 사용자 지정 컨트롤에 대 한 태그 접두사 별칭을 지정할 수 있도록 하는 어셈블리 수준 특성을 정의 하는 방법을 보여 줍니다. 이 특성은 자동으로 생성 하려면 Microsoft Visual Studio와 같은 도구에서 사용을 @ Register 사용자 지정 컨트롤이 사용 되는 웹 페이지 지시문입니다.


using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

[assembly:TagPrefix("CustomControls", "custom")]

namespace CustomControls
{

    // Simple custom control
    public class MyCS_Control : Control
      {
            private String message = "Hello";
            
            public virtual String Message
            {
                  get
                  {
                        return message;
                  }
                  set
                  {
                        message = value;
                  }
            }
            
            [System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name="FullTrust")] 
            protected override void Render( HtmlTextWriter writer)
            {
            writer.Write("<span style='background-color:aqua; font:8pt tahoma, verdana;'> "
                        + this.Message + "<br>" + "C# version. The time on the server is " + System.DateTime.Now.ToLongTimeString()
                        + "</span>");
            }
      }
}

Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls

<assembly: TagPrefix("CustomControls", "custom")> _

Namespace CustomControls
   
   ' Simple custom control
   Public Class MyVB_Control 
   Inherits Control
      Private message As String = "Hello"
      
      Public  Property getMessage() As String
         Get
            Return message
         End Get
         Set (ByVal value As String)
            message = value
         End Set
      End Property
      
      <System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.Demand, Name:="FullTrust")> _
      Protected Overrides Sub Render(writer As HtmlTextWriter)
         writer.Write(("<span style='background-color:aqua; font:8pt tahoma, verdana;'> " + Me.getMessage + "<br>" + "VB version. The time on the server is " + System.DateTime.Now.ToLongTimeString() + "</span>"))
      End Sub
   End Class
End Namespace 'CustomControls

설명

사용자 지정 컨트롤을 정의 하 고 모든 코드 하기 전에 다음과 같이이 클래스 생성자를 호출 해야 합니다.

[assembly:TagPrefix(namespace, tag)]

적용 대상