This documentation is archived and is not being maintained.

HtmlTextWriter.RenderBeforeTag Method

Writes any text or spacing that occurs before the opening tag of a markup element.

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

protected virtual string RenderBeforeTag ()
protected String RenderBeforeTag ()
protected function RenderBeforeTag () : String
Not applicable.

Return Value

The text or spacing to write before the markup element opening tag. If not overridden, a null reference (Nothing in Visual Basic).

The RenderBeforeTag method can be useful if you want to render additional opening tags before the opening tag of the intended element.

Notes to Implementers: The HtmlTextWriter class implementation of the RenderBeforeTag method returns a null reference (Nothing in Visual Basic). Override RenderBeforeTag if you want to write text or spacing ahead of the element opening tag.

The following code example shows how to override the RenderBeforeTag method to determine whether a class that is derived from the HtmlTextWriter class is about to render a <label> element. If so, the RenderBeforeTag override inserts the opening tag of a <font> element immediately before the <label> element. If it is not rendering a <label> element, the RenderBeforeTag base method is used.

// 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();
    }
}

// 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 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(get_TagName(), "label") == 0) {
        return "<font color=\"red\">";
    }
        // If a Label is not being rendered, use 
        // the base RenderBeforeTag method.
    else  {
        return super.RenderBeforeTag();
    }
} //RenderBeforeTag

Windows 98, Windows Server 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

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