TagPrefixAttribute Class


定义在网页中用于标识自定义控件的标记前缀。Defines the tag prefix used in a Web page to identify custom controls. 无法继承此类。This class cannot be inherited.

public ref class TagPrefixAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple=true)]
public sealed class TagPrefixAttribute : Attribute
type TagPrefixAttribute = class
    inherit Attribute
Public NotInheritable Class TagPrefixAttribute
Inherits Attribute


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
                        return message;
                        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
            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 


TagPrefixAttribute 类定义了一个程序集级别的特性,该特性需要为自定义控件指定标记前缀别名。The TagPrefixAttribute class defines an assembly-level attribute needed to specify tag prefix aliases for custom controls. 此属性由 Microsoft Visual Studio 工具(如)在使用自定义控件的 "ASP.NET" 页中自动生成 Register 指令。This attribute is used by tools such as Microsoft Visual Studio to automatically generate a Register directive in the ASP.NET page where the custom controls are used.

此指令将标记前缀注册到命名空间。This directive registers the tag prefix with a namespace. 此外,它还指定自定义控件代码实现所在的程序集。Moreover, it specifies the assembly where the custom control code implementation resides. 使用此指令后,可以通过声明方式在网页中使用自定义控件。With this directive in place, you can use custom controls in a Web page declaratively.

有关使用特性的详细信息,请参阅特性For more information about using attributes, see Attributes.


TagPrefixAttribute(String, String)

初始化 TagPrefixAttribute 类的新实例。Initializes a new instance of the TagPrefixAttribute class.



获取指定控件的命名空间前缀。Gets the namespace prefix for the specified control.


获取指定控件的标记前缀。Gets the tag prefix for the specified control.


在派生类中实现时,获取此 Attribute 的唯一标识符。When implemented in a derived class, gets a unique identifier for this Attribute.

(Inherited from Attribute)



返回一个值,该值指示此实例是否与指定的对象相等。Returns a value that indicates whether this instance is equal to a specified object.

(Inherited from Attribute)

返回此实例的哈希代码。Returns the hash code for this instance.

(Inherited from Attribute)

获取当前实例的 TypeGets the Type of the current instance.

(Inherited from Object)

在派生类中重写时,指示此实例的值是否是派生类的默认值。When overridden in a derived class, indicates whether the value of this instance is the default value for the derived class.

(Inherited from Attribute)

当在派生类中重写时,返回一个指示此实例是否等于指定对象的值。When overridden in a derived class, returns a value that indicates whether this instance equals a specified object.

(Inherited from Attribute)

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(Inherited from Object)

返回表示当前对象的字符串。Returns a string that represents the current object.

(Inherited from Object)

Explicit Interface Implementations

_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

将一组名称映射为对应的一组调度标识符。Maps a set of names to a corresponding set of dispatch identifiers.

(Inherited from Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

检索对象的类型信息,然后可以使用该信息获取接口的类型信息。Retrieves the type information for an object, which can be used to get the type information for an interface.

(Inherited from Attribute)

检索对象提供的类型信息接口的数量(0 或 1)。Retrieves the number of type information interfaces that an object provides (either 0 or 1).

(Inherited from Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

提供对某一对象公开的属性和方法的访问。Provides access to properties and methods exposed by an object.

(Inherited from Attribute)

Applies to

See also