This documentation is archived and is not being maintained.

HtmlTextWriter::TagName Property

Gets or sets the tag name of the markup element being rendered.

Namespace:  System.Web.UI
Assembly:  System.Web (in System.Web.dll)

protected:
property String^ TagName {
	String^ get ();
	void set (String^ value);
}

Property Value

Type: System::String
The tag name of the markup element being rendered.

The TagName property is of use only to classes that inherit from the HtmlTextWriter class. You should read or set the TagName property only in RenderBeginTag method calls; this is the only time it is set to a consistent value.

The following code example demonstrates an overridden version of the RenderBeforeTag method in a class that derives from the HtmlTextWriter class. The code example checks whether the element to render is a <label> element by calling the String::Compare method, and then passing the TagName property value and a string, "label", as the parameter arguments. If a <label> element is about to be rendered, the opening tag of a <font> element, with a color attribute set to red, is rendered before the <label> element's opening tag. If the element to render is not a <label> element, the base class's version of the RenderBeforeTag method is called.

// Override the RenderBeforeTag method to add the 
// opening tag of a Font element before the 
// opening tag of any Label elements rendered by this 
// custom markup writer. 
virtual String^ RenderBeforeTag() override
{
   // Compare the TagName property value to the 
   // String* label to determine whether the element to 
   // be rendered is a Label. If it is a Label, 
   // the opening tag of the Font element, with a Color 
   // style attribute set to red, is added before 
   // the Label. 
   if ( String::Compare( TagName, "label" ) == 0 )
   {
      return "<font color=\"red\">";
   }
   // If a Label is not being rendered, use 
   // the base RenderBeforeTag method. 
   else
   {
      return __super::RenderBeforeTag();
   }
}

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
Show: