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

定义

确定指定的 cHTML 特性及其值是否将呈现给请求页。Determines whether the specified cHTML attribute and its value are rendered to the requesting page. 可以在从 OnAttributeRender(String, String, HtmlTextWriterAttribute) 类派生的类中重写 ChtmlTextWriter 方法,以筛选出不希望在支持 cHTML 的设备上呈现的特性。You can override the OnAttributeRender(String, String, HtmlTextWriterAttribute) method in classes that derive from the ChtmlTextWriter class to filter out attributes that you do not want to render on devices that support cHTML.

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

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

value
String

分配给 name 的值。The value assigned to name.

key
HtmlTextWriterAttribute

HtmlTextWriterAttribute 关联的 nameThe HtmlTextWriterAttribute associated with name.

返回

Boolean

如果将特性及其值写入 ChtmlTextWriter 输入流,则为 true;否则为 falsetrue to write the attribute and its value to the ChtmlTextWriter output stream; otherwise, false.

示例

下面的代码示例演示如何使用重写方法的自定义类, OnAttributeRender 以防止将 bgcolor 特性写入 cHTML 输出流中。The following code example demonstrates how to use a custom class that overrides the OnAttributeRender method to prevent the bgcolor attribute from being written to the cHTML output stream. 然后,它从类中调用基方法提供的功能 OnAttributeRender ChtmlTextWriter ,以确保也使用其默认行为。It then calls the functionality that is provided by the base OnAttributeRender method from the ChtmlTextWriter class to ensure that its default behavior is used, too.

此代码示例是为类提供的更大示例的一部分 ChtmlTextWriterThis code example is part of a larger example provided for the ChtmlTextWriter class.

// Override the OnAttributeRender method to
// not render the bgcolor attribute, which is
// not supported in CHTML.
protected override bool OnAttributeRender(string name, string value, HtmlTextWriterAttribute key)
{
    if (String.Equals("bgcolor", name))
    {
        return false;
    }
    
    // Call the ChtmlTextWriter version of the
    // the OnAttributeRender method.
    return base.OnAttributeRender(name, value, key);
}
' Override the OnAttributeRender method to
' not render the bgcolor attribute, which is 
' not supported in CHTML.
Protected Overrides Function OnAttributeRender(ByVal name As String, ByVal value As String, ByVal key As HtmlTextWriterAttribute) As Boolean
    If (String.Equals("bgcolor", name)) Then
        Return False
    End If

    ' Call the ChtmlTextWriter version of 
    ' the OnAttributeRender method.
    MyBase.OnAttributeRender(name, value, key)

End Function

注解

默认情况下,该 OnAttributeRender 方法阻止全局禁止显示在属性中列出的属性 GlobalSuppressedAttributes 和元素特定的、禁止 SuppressedAttributes 写入到输出流中的属性中列出的属性。By default, the OnAttributeRender method prevents globally suppressed attributes that are listed in the GlobalSuppressedAttributes property and element-specific, suppressed attributes that are listed in the SuppressedAttributes property from being written to the output stream. 可以 OnAttributeRender 在派生自类的类中重写方法的行为 ChtmlTextWriterYou can override the behavior of the OnAttributeRender method in classes that are derived from the ChtmlTextWriter class.

适用于

另请参阅