Language

HtmlTextWriter.OnStyleAttributeRender メソッド

定義

指定したマークアップ スタイル属性とその値を現在のマークアップ要素にレンダリングできるかどうかを判断します。

protected:
 virtual bool OnStyleAttributeRender(System::String ^ name, System::String ^ value, System::Web::UI::HtmlTextWriterStyle key);
protected virtual bool OnStyleAttributeRender(string name, string value, System.Web.UI.HtmlTextWriterStyle key);
abstract member OnStyleAttributeRender : string * string * System.Web.UI.HtmlTextWriterStyle -> bool
override this.OnStyleAttributeRender : string * string * System.Web.UI.HtmlTextWriterStyle -> bool
Protected Overridable Function OnStyleAttributeRender (name As String, value As String, key As HtmlTextWriterStyle) As Boolean

パラメーター

name
String

レンダリングするスタイル属性の名前を含む文字列。

value
String

スタイル属性に割り当てられている値を含む文字列。

key
HtmlTextWriterStyle

スタイル属性に関連付けられている HtmlTextWriterStyle 。

返品

常に true です。

例

次のコード例は、 OnStyleAttributeRender メソッドをオーバーライドする方法を示しています。 Color スタイル属性がレンダリングされても、Color値がpurpleされていない場合、OnStyleAttributeRenderオーバーライドでは、AddStyleAttribute メソッドを使用してColor属性をpurpleに設定します。

// If a color style attribute is to be rendered,
// compare its value to purple. If it is not set to
// purple, add the style attribute and set the value
// to purple, then return false.
protected override bool OnStyleAttributeRender(string name,
    string value,
    HtmlTextWriterStyle key)
{

    if (key == HtmlTextWriterStyle.Color)
    {
        if (string.Compare(value, "purple") != 0)
        {
            AddStyleAttribute("color", "purple");
            return false;
        }
    }

    // If the style attribute is not a color attribute,
    // use the base functionality of the
    // OnStyleAttributeRender method.
    return base.OnStyleAttributeRender(name, value, key);
}
' If a color style attribute is to be rendered,
' compare its value to purple. If it is not set to
' purple, add the style attribute and set the value
' to purple, then return false.
Protected Overrides Function OnStyleAttributeRender(name As String, _
    value As String, _
    key As HtmlTextWriterStyle) _
As Boolean

    If key = HtmlTextWriterStyle.Color Then
        If [String].Compare(value, "purple") <> 0 Then
            AddStyleAttribute("color", "purple")
            Return False
        End If
    End If

    ' If the style attribute is not a color attribute,
    ' use the base functionality of the
    ' OnStyleAttributeRender method.
    Return MyBase.OnStyleAttributeRender(name, value, key)
End Function 'OnStyleAttributeRender

注釈

HtmlTextWriter メソッドのOnStyleAttributeRender クラスの実装では、常にtrueが返されます。 OnStyleAttributeRenderオーバーライドは、スタイル属性をページにレンダリングするかどうかを決定できます。

注意 (継承者)

HtmlTextWriter クラスから継承する場合は、OnStyleAttributeRender(String, String, HtmlTextWriterStyle) メソッドをオーバーライドしてfalseを返し、スタイル属性がまったくレンダリングされたり、特定の要素にレンダリングされたり、特定のマークアップ言語用にレンダリングされたりしないようにすることができます。 たとえば、HtmlTextWriterから派生したオブジェクトをcolor スタイル属性を<p>要素にレンダリングしたくない場合は、OnStyleAttributeRender(String, String, HtmlTextWriterStyle)をオーバーライドし、falseがnameを渡し、colorプロパティ値がTagNameされたときにpを返すことができます。

適用対象

こちらもご覧ください