Export (0) Print
Expand All

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 string TagName { get; set; }

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. 
protected override string RenderBeforeTag()
{
    // 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 base.RenderBeforeTag();
    }
}


.NET Framework

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

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

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

Community Additions

ADD
Show:
© 2014 Microsoft