XhtmlTextWriter.OnStyleAttributeRender Method

Definition

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

protected override bool OnStyleAttributeRender (string name, string value, System.Web.UI.HtmlTextWriterStyle key);

Parameters

name
String

The XHTML style attribute to render.

value
String

The value assigned to the XHTML style attribute.

key
HtmlTextWriterStyle

The HtmlTextWriterStyle enumeration value associated with the XHTML style attribute.

Returns

true if the style attribute is rendered; otherwise, false.

Examples

The following code example demonstrates how to override the OnStyleAttributeRender method to check whether a Color attribute is being rendered for any of the elements that are rendered by this text writer. If a Color attribute is rendered, the code checks whether its value is purple. If the value is purple, the OnStyleAttributeRender method returns false and the attribute and its value are not rendered. If the Color attribute is set to any other value, the OnStyleAttributeRender method returns true and the attribute and its value are rendered. If the key parameter of the OnAttributeRender method does not match the Color attribute, the base functionality of the OnStyleAttributeRender method is called, as defined in the XhtmlTextWriter class.

This code example is part of a larger example provided for the XhtmlTextWriter class.

// Override the OnStyleAttributeRender
// method to prevent this text writer 
// from rendering purple text.
protected override bool OnStyleAttributeRender(string name, 
    string value, 
    HtmlTextWriterStyle key)
{
    if (key == HtmlTextWriterStyle.Color)
    {
        if (String.Compare(value, "purple") == 0)
        {
            return false;
        }
        else
        {
            return true;
        }
    }
    else
    {
        return base.OnStyleAttributeRender(name, value, key);
    }        
}

Applies to

Product Versions
.NET Framework 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