TagPrefixAttribute(String, String) 建構函式
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
初始化 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)]