This documentation is archived and is not being maintained.

HtmlTextWriter.OnAttributeRender Method

Determines whether the specified markup attribute and its value can be rendered to the current markup element.

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

protected virtual bool OnAttributeRender(
	string name,
	string value,
	HtmlTextWriterAttribute key


Type: System.String
A string containing the name of the attribute to render.
Type: System.String
A string containing the value that is assigned to the attribute.
Type: System.Web.UI.HtmlTextWriterAttribute
The HtmlTextWriterAttribute associated with the markup attribute.

Return Value

Type: System.Boolean
Always true.

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

Notes to Inheritors

If you inherit from the HtmlTextWriter class, you can override the OnAttributeRender method to return false to prevent an attribute from being rendered at all, being rendered on a particular element, or being rendered for a particular markup. For example, if you do not want the object derived from HtmlTextWriter to render the bgcolor attribute to <table> elements, you can override the OnAttributeRender and return false when name passes bgcolor and the TagName property value is table.

The following code example shows how to override the OnAttributeRender method. If a Size attribute is rendered, but the Size value is not 30pt, the OnAttributeRender override calls the AddAttribute method to add a Size attribute and set its value to 30pt.

// If a size attribute is to be rendered, compare its value to 30 point.
// If it is not set to 30 point, add the attribute and set the value to 30,
// then return false.
protected override bool OnAttributeRender(string name,
    string value,
    HtmlTextWriterAttribute key)

    if (key == HtmlTextWriterAttribute.Size)
        if (string.Compare(value, "30pt") != 0)
            AddAttribute("size", "30pt");
            return false;

    // If the attribute is not a size attribute, use
    // the base functionality of the OnAttributeRender method.
    return base.OnAttributeRender(name, value, key);

.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.