Export (0) Print
Expand All

XhtmlTextWriter.OnAttributeRender Method

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

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

protected override bool OnAttributeRender (
	string name,
	string value,
	HtmlTextWriterAttribute key
)
protected boolean OnAttributeRender (
	String name, 
	String value, 
	HtmlTextWriterAttribute key
)
protected override function OnAttributeRender (
	name : String, 
	value : String, 
	key : HtmlTextWriterAttribute
) : boolean
Not applicable.

Parameters

name

The XHTML attribute to render.

value

The value assigned to the XHTML attribute.

key

The HtmlTextWriterAttribute enumeration value associated with the XHTML attribute.

Return Value

true if the attribute is rendered to the page; otherwise, false.

The following code example demonstrates how to override the OnAttributeRender method to check whether a size attribute is rendered for any of the elements that are rendered by this text writer. If a size attribute is rendered, the code checks whether its value is 8 point. If so, the OnAttributeRender method returns true, allowing the attribute and its value to render. If the value is other than 8 point, the OnAttributeRender method returns false, and the attribute and its value are not rendered. If the key parameter of the OnAttributeRender method does not match the Size attribute, the base functionality of the OnAttributeRender 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 OnAttributeRender method to 
// allow this text writer to render only eight-point 
// text size.
protected override bool OnAttributeRender(string name, 
  string value, 
  HtmlTextWriterAttribute key) 
{
    if (key == HtmlTextWriterAttribute.Size)
    {
        if (String.Compare(value, "8pt") == 0)
        {
            return true;
        }
        else
        {
           return false;
        } 
     }
     else
     {
         return base.OnAttributeRender(name, value, key);
     }

 }

// Override the OnAttributeRender method to 
// allow this text writer to render only eight-point 
// text size.
protected boolean OnAttributeRender(String name, String value,
    HtmlTextWriterAttribute key)
{
    if (key.Equals(HtmlTextWriterAttribute.Size)) {
        if (String.Compare(value, "8pt") == 0) {
            return true;
        }
        else {
            return false;
        }
    }
    else {
        return super.OnAttributeRender(name, value, key);
    }
} //OnAttributeRender

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

Community Additions

ADD
Show:
© 2014 Microsoft