Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

HtmlTextWriter.RenderBeforeContent Method

Writes any text or spacing before the content and after the opening tag of a markup element.

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

protected virtual string RenderBeforeContent()

Return Value

Type: System.String
The text or spacing to write prior to the content of the element. If not overridden, RenderBeforeContent returns null.

The RenderBeforeContent method can be useful if you want to insert child elements into the current markup element before the inner markup.

Notes to Inheritors

The HtmlTextWriter class implementation of the RenderBeforeContent method returns null. Override RenderBeforeContent if you want to write text or spacing after the opening tag but ahead of the element content.

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


// 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, 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:
© 2015 Microsoft