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

戻り値

Boolean

常に true

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

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

注釈

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

注意 (継承者)

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

適用対象

こちらもご覧ください