Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
OnStyleAttributeRender Method

HtmlTextWriter.OnStyleAttributeRender Method

Determines whether the specified markup style 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 OnStyleAttributeRender (
	string name,
	string value,
	HtmlTextWriterStyle key
)
protected boolean OnStyleAttributeRender (
	String name, 
	String value, 
	HtmlTextWriterStyle key
)
protected function OnStyleAttributeRender (
	name : String, 
	value : String, 
	key : HtmlTextWriterStyle
) : boolean
Not applicable.

Parameters

name

A string containing the name of the style attribute to render.

value

A string containing the value that is assigned to the style attribute.

key

The HtmlTextWriterStyle associated with the style attribute.

Return Value

Always true.

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

Notes to Inheritors: If you inherit from the HtmlTextWriter class, you can override the OnStyleAttributeRender method to return false to prevent a style attribute from being rendered at all, being rendered on a particular element, or being rendered for a particular markup language. For example, if you do not want the object that is derived from HtmlTextWriter to render the color style attribute to a <p> element, you can override the OnStyleAttributeRender and return false when name passes color and the TagName property value is p.

The following code example shows how to override the OnStyleAttributeRender method. If a Color style attribute is rendered, but the Color value is not purple, the OnStyleAttributeRender override uses the AddStyleAttribute method to set the Color attribute to purple.

// If a color style attribute is to be rendered,
// compare its value to purple. If it is not set to
// purple, add the style attribute and set the value
// to purple, then return false.
protected override bool OnStyleAttributeRender(string name,
    string value,
    HtmlTextWriterStyle key)
{

    if (key == HtmlTextWriterStyle.Color)
    {
        if (string.Compare(value, "purple") != 0)
        {
            AddStyleAttribute("color", "purple");
            return false;
        }
    }

    // If the style attribute is not a color attribute,
    // use the base functionality of the
    // OnStyleAttributeRender method.
    return base.OnStyleAttributeRender(name, value, key);
}

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

Community Additions

ADD
Show:
© 2015 Microsoft