Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

HtmlTextWriter.OnTagRender Method

Determines whether the specified markup element will be rendered to the requesting page.

Namespace:  System.Web.UI
Assembly:  System.Web (in System.Web.dll)
protected virtual bool OnTagRender(
	string name,
	HtmlTextWriterTag key
)

Parameters

name
Type: System.String

A string containing the name of the element to render.

key
Type: System.Web.UI.HtmlTextWriterTag

The HtmlTextWriterTag associated with the element.

Return Value

Type: System.Boolean
Always true.

The HtmlTextWriter class implementation of the OnTagRender method always returns true. The OnTagRender overrides can determine whether an element will be rendered to the page.

Notes to Inheritors

If you inherit from the HtmlTextWriter class, you can override the OnTagRender method to return false to prevent a markup element from being rendered at all or for a particular markup language. For example, if you do not want the object that is derived from HtmlTextWriter to render the <font> element, you can override the OnTagRender method to return false when a page is requested that contains a <font> element.

The following code example shows how to override the OnTagRender method. If a Font element is being rendered, the OnTagRender override uses the IsAttributeDefined method to determine whether a Size attribute is being rendered. If not, it uses the AddAttribute method to create a Size attribute and set its value to 20pt.

// If a <font> element is to be rendered, check whether it contains 
// a size attribute. If it does not, add one and set its value to 
// 20 points, then return true. 
protected override bool OnTagRender(string name, HtmlTextWriterTag key)
{

    if (key == HtmlTextWriterTag.Font)
    {
        if (!(IsAttributeDefined(HtmlTextWriterAttribute.Size)))
        {
            AddAttribute(HtmlTextWriterAttribute.Size, "20pt");
            return true;
        }
    }

    // If the element is not a <font> element, use 
    // the base functionality of the OnTagRenderMethod. 
    return base.OnTagRender(name, key);
}

.NET Framework

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

Windows Phone 8.1, Windows Phone 8, 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.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.