HtmlTextWriter.RenderAfterContent Method

Definition

Writes any text or spacing that occurs after the content and before the closing tag of the markup element to the markup output stream.

C#
protected virtual string RenderAfterContent();

Returns

A string that contains the spacing or text to write after the content of the element.

Examples

The following code example shows how to override the RenderAfterContent method in a class derived from the HtmlTextWriter class to determine whether a <label> element is being rendered. If so, the RenderAfterContent override inserts the closing tag of a <font> element immediately before the closing tag of the <label> element. If an element other than <label> is being rendered, the RenderAfterContent base method is used.

C#
// Override the RenderAfterContent method to render
// the closing tag of a font element if the 
// rendered tag is a label element.
protected override string RenderAfterContent()
{
    // Check to determine whether the element being rendered
    // is a label element. If so, render the closing tag
    // of the font element; otherwise, call the base method.
    if (TagKey == HtmlTextWriterTag.Label)
    {
        return "</font>";
    }
    else
    {
        return base.RenderAfterContent();
    }
}

Remarks

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

Notes to Inheritors

The HtmlTextWriter class implementation of the RenderAfterContent() method returns null. Override RenderAfterContent() if you want to write text or spacing after the element content but before the closing tag.

Applies to

Proizvod Verzije
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

See also