Edit

Share via


HtmlTextWriter.TagKey Property

Definition

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

protected:
 property System::Web::UI::HtmlTextWriterTag TagKey { System::Web::UI::HtmlTextWriterTag get(); void set(System::Web::UI::HtmlTextWriterTag value); };
protected System.Web.UI.HtmlTextWriterTag TagKey { get; set; }
member this.TagKey : System.Web.UI.HtmlTextWriterTag with get, set
Protected Property TagKey As HtmlTextWriterTag

Property Value

The markup element that is having its opening tag rendered.

Exceptions

The property value cannot be set.

Examples

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.

virtual String^ RenderBeforeContent() override
{
   
   // 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 __super::RenderBeforeContent();
   }
}
// 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();
    }
}
' Override the RenderBeforeContent method to write
' a font element that applies red to the text in a Label element.
Protected Overrides Function RenderBeforeContent() As String
    ' 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 Then
        Return "<font color=""red"">"
    Else
        Return MyBase.RenderBeforeContent()
    End If
End Function 'RenderBeforeContent

Remarks

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.

Applies to

See also