Export (0) Print
Expand All

HtmlTextWriter.TagKey Property

Gets or sets the HtmlTextWriterTag value for the specified markup element.

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

protected HtmlTextWriterTag TagKey { get; set; }

Property Value

Type: System.Web.UI.HtmlTextWriterTag
The markup element that is having its opening tag rendered.

ExceptionCondition
ArgumentOutOfRangeException

The property value cannot be set.

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

The following code example demonstrates an overridden version of the RenderBeforeContent method in a class that derives from the HtmlTextWriter class. It uses the value of the TagKey property to determine whether a server control using the custom HtmlTextWriter object is rendering a <label> markup element. If it is, a <font> element with a color attribute set to red is returned to modify the formatting of the <label> element's text.

// Override the RenderBeforeContent method to write 
// a font element that applies red to the text in a Label element. 
protected override string RenderBeforeContent()
{
    // Check to determine whether the element being rendered 
    // is a label element. If so, render the opening tag 
    // of the font element; otherwise, call the base method. 
    if (TagKey == HtmlTextWriterTag.Label)
    {
        return "<font color=\"red\">";
    }
    else
    {
        return base.RenderBeforeContent();
    }
}

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

Show:
© 2014 Microsoft