XhtmlTextWriter.OnAttributeRender(String, String, HtmlTextWriterAttribute) 方法

定义

确定是否可以将指定的 XHTML 特性及其值呈现给当前的加价元素。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

参数

name
String

要呈现的 XHTML 特性。The XHTML attribute to render.

value
String

分配给 XHTML 特性的值。The value assigned to the XHTML attribute.

key
HtmlTextWriterAttribute

与 XHTML 特性关联的 HtmlTextWriterAttribute 枚举值。The HtmlTextWriterAttribute enumeration value associated with the XHTML attribute.

返回

Boolean

如果该特性呈现到页,则为 true;否则为 falsetrue if the attribute is rendered to the page; otherwise, false.

示例

下面的代码示例演示如何重写 OnAttributeRender 方法,以检查是否为 size 此文本编写器呈现的任何元素呈现特性。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. 如果 size 呈现属性,则代码将检查其值是否为8磅。If a size attribute is rendered, the code checks whether its value is 8 point. 如果是这样,则该 OnAttributeRender 方法返回 true ,允许属性及其值呈现。If so, the OnAttributeRender method returns true, allowing the attribute and its value to render. 如果值不是8点,则方法将 OnAttributeRender 返回 false ,并且不呈现特性及其值。If the value is other than 8 point, the OnAttributeRender method returns false, and the attribute and its value are not rendered. 如果方法的键参数 OnAttributeRender 与特性不匹配,则将 Size 调用方法的基本功能 OnAttributeRender ,如类中所定义 XhtmlTextWriterIf 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.

此代码示例是为类提供的更大示例的一部分 XhtmlTextWriterThis 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

适用于

另请参阅