Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
 OnAttributeRender Method
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Class Library
XhtmlTextWriter..::.OnAttributeRender Method

Updated: November 2007

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)

Visual Basic (Declaration)
Protected Overrides Function OnAttributeRender ( _
    name As String, _
    value As String, _
    key As HtmlTextWriterAttribute _
) As Boolean
Visual Basic (Usage)
Dim name As String
Dim value As String
Dim key As HtmlTextWriterAttribute
Dim returnValue As Boolean

returnValue = Me.OnAttributeRender(name, _
    value, key)
C#
protected override bool OnAttributeRender(
    string name,
    string value,
    HtmlTextWriterAttribute key
)
Visual C++
protected:
virtual bool OnAttributeRender(
    String^ name, 
    String^ value, 
    HtmlTextWriterAttribute key
) override
J#
protected boolean OnAttributeRender(
    String name,
    String value,
    HtmlTextWriterAttribute key
)
JScript
protected override function OnAttributeRender(
    name : String, 
    value : String, 
    key : HtmlTextWriterAttribute
) : boolean

Parameters

name
Type: System..::.String

The XHTML attribute to render.

value
Type: System..::.String

The value assigned to the XHTML attribute.

key
Type: System.Web.UI..::.HtmlTextWriterAttribute

The HtmlTextWriterAttribute enumeration value associated with the XHTML attribute.

Return Value

Type: System..::.Boolean

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.

Visual Basic
' Override the OnAttributeRender method to 
' allow this text writer to render only eight-point 
' text size.
Overrides Protected Function OnAttributeRender(ByVal name As String, _
  ByVal value As String, _
  ByVal key As HtmlTextWriterAttribute _
) As Boolean
   If key = HtmlTextWriterAttribute.Size Then
      If String.Compare(value, "8pt") = 0 Then
         Return True
      Else
         Return False
      End If 
   Else
      Return MyBase.OnAttributeRender(name, value, key)
   End If
End Function

C#
// 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);
     }

 }

J#
// 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 Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker