HtmlTextWriter.OnStyleAttributeRender Metod

Definition

Avgör om det angivna markeringsformatattributet och dess värde kan återges till det aktuella markeringselementet.

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

Parametrar

name
String

En sträng som innehåller namnet på formatattributet som ska återges.

value
String

En sträng som innehåller värdet som har tilldelats formatattributet.

key
HtmlTextWriterStyle

Associerad HtmlTextWriterStyle med formatattributet.

Returer

Alltid true.

Exempel

I följande kodexempel visas hur du åsidosätter OnStyleAttributeRender metoden. Om ett Color formatattribut återges, men Color värdet inte purpleär , OnStyleAttributeRender använder åsidosättningen AddStyleAttribute metoden för att ange Color attributet till 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

Kommentarer

Klassimplementeringen HtmlTextWriterOnStyleAttributeRender av metoden returnerar truealltid . Åsidosättningarna OnStyleAttributeRender kan avgöra om ett formatattribut ska återges på sidan.

Anteckningar till arvingar

Om du ärver från HtmlTextWriter klassen kan du åsidosätta OnStyleAttributeRender(String, String, HtmlTextWriterStyle) metoden för att återgå false för att förhindra att ett formatattribut återges alls, återges på ett visst element eller återges för ett visst markeringsspråk. Om du till exempel inte vill att objektet som härleds från HtmlTextWriter ska återge formatattributet color till ett <p> element kan du åsidosätta OnStyleAttributeRender(String, String, HtmlTextWriterStyle) och returnera false när name det skickas color och egenskapsvärdet TagName är p.

Gäller för

Se även