TagPrefixAttribute 類別

定義

定義網頁中使用的標記前置詞,以辨認自訂控制項。 此類別無法獲得繼承。

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

範例


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

備註

類別 TagPrefixAttribute 會定義自訂控制項指定標籤前置詞別名所需的元件層級屬性。 此工具會使用此屬性,例如Microsoft Visual Studio,在使用自訂控制項的 ASP.NET 網頁中自動產生 Register 指示詞。

這個指示詞會向命名空間註冊標籤前置詞。 此外,它會指定自訂控制項程式碼實作所在的元件。 有了這個指示詞,您就可以以宣告方式在網頁中使用自訂控制項。

如需使用屬性的詳細資訊,請參閱 屬性

建構函式

TagPrefixAttribute(String, String)

初始化 TagPrefixAttribute 類別的新執行個體。

屬性

NamespaceName

取得指定控制項的命名空間前置詞。

TagPrefix

取得指定控制項的標記前置詞。

TypeId

在衍生類別中實作時,取得這個 Attribute 的唯一識別碼。

(繼承來源 Attribute)

方法

Equals(Object)

傳回值,這個值指出此執行個體是否與指定的物件相等。

(繼承來源 Attribute)
GetHashCode()

傳回這個執行個體的雜湊碼。

(繼承來源 Attribute)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
IsDefaultAttribute()

在衍生類別中覆寫時,表示這個執行個體的值是衍生類別的預設值。

(繼承來源 Attribute)
Match(Object)

在衍生類別中覆寫時,會傳回值,表示這個執行個體是否等於指定物件。

(繼承來源 Attribute)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

明確介面實作

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

將一組名稱對應至一組對應的分派識別項 (Dispatch Identifier)。

(繼承來源 Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

擷取物件的類型資訊,可以用來取得介面的類型資訊。

(繼承來源 Attribute)
_Attribute.GetTypeInfoCount(UInt32)

擷取物件提供的類型資訊介面數目 (0 或 1)。

(繼承來源 Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

提供物件所公開的屬性和方法的存取權。

(繼承來源 Attribute)

適用於

另請參閱