TagPrefixAttribute Class
Defines the tag prefix used in a Web page to identify custom controls. This class cannot be inherited.
For a list of all members of this type, see TagPrefixAttribute Members.
System.Object
System.Attribute
System.Web.UI.TagPrefixAttribute
[Visual Basic] <AttributeUsage(AttributeTargets.Assembly)> NotInheritable Public Class TagPrefixAttribute Inherits Attribute [C#] [AttributeUsage(AttributeTargets.Assembly)] public sealed class TagPrefixAttribute : Attribute [C++] [AttributeUsage(AttributeTargets::Assembly)] public __gc __sealed class TagPrefixAttribute : public Attribute [JScript] public AttributeUsage(AttributeTargets.Assembly) class TagPrefixAttribute extends Attribute
Thread Safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Remarks
The TagPrefixAttribute defines an assembly-level attribute needed to specify tag prefix aliases for custom controls. This attribute is used by tools such as 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 Extending Metadata Using Attributes.
Example
[Visual Basic] Imports System 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 'Render End Class 'MyControl End Namespace 'CustomControls [C#] 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>"); } } } [C++] #using <mscorlib.dll> #using <System.Web.dll> #using <System.dll> using namespace System; using namespace System::Web; using namespace System::Web::UI; using namespace System::Web::UI::WebControls; [assembly:TagPrefixAttribute(S"CustomControls", S"custom")]; namespace CustomControls { // Simple custom control public __gc class MyCS_Control : public Control { private: String* message; public: MyCS_Control() { message = S"Hello"; } __property virtual String * get_Message() { return message; } __property virtual void set_Message(String * value) { message = value; } protected: [System::Security::Permissions::PermissionSet(System::Security::Permissions::SecurityAction::Demand, Name="FullTrust")] void Render(HtmlTextWriter* writer) { writer->Write(S"<span style='background-color:aqua; font:8pt tahoma, verdana;'> {0} <br>C# version. The time on the server is {1}</span>", this->Message, DateTime::Now.ToLongTimeString()); } }; }
[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Namespace: System.Web.UI
Platforms: Windows 2000, Windows XP Professional, Windows Server 2003 family
Assembly: System.Web (in System.Web.dll)
See Also
TagPrefixAttribute Members | System.Web.UI Namespace | @ Register | Custom Server Control Syntax | Attribute