편집

다음을 통해 공유


XhtmlTextWriter.OnAttributeRender Method

Definition

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

protected:
 override bool OnAttributeRender(System::String ^ name, System::String ^ value, System::Web::UI::HtmlTextWriterAttribute key);
protected override bool OnAttributeRender (string name, string value, System.Web.UI.HtmlTextWriterAttribute key);
override this.OnAttributeRender : string * string * System.Web.UI.HtmlTextWriterAttribute -> bool
Protected Overrides Function OnAttributeRender (name As String, value As String, key As HtmlTextWriterAttribute) As Boolean

Parameters

name
String

The XHTML attribute to render.

value
String

The value assigned to the XHTML attribute.

key
HtmlTextWriterAttribute

The HtmlTextWriterAttribute enumeration value associated with the XHTML attribute.

Returns

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

Examples

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

Applies to

See also