HtmlTextWriter.OnStyleAttributeRender(String, String, HtmlTextWriterStyle) Method

Definition

Détermine si l'attribut de style de balisage spécifié et sa valeur peuvent être rendus dans l'élément de balisage actuel.Determines whether the specified markup style attribute and its value can be rendered to the current markup element.

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

Parameters

name
String

Chaîne contenant le nom de l'attribut de style à restituer.A string containing the name of the style attribute to render.

value
String

Chaîne contenant la valeur assignée à l'attribut de style.A string containing the value that is assigned to the style attribute.

key
HtmlTextWriterStyle

HtmlTextWriterStyle associé à l'attribut de style.The HtmlTextWriterStyle associated with the style attribute.

Returns

Boolean

A toujours la valeur true.Always true.

Examples

L’exemple de code suivant montre comment substituer la méthode OnStyleAttributeRender.The following code example shows how to override the OnStyleAttributeRender method. Si un attribut de style Color est rendu, mais que la valeur de Color n’est pas purple, la substitution de OnStyleAttributeRender utilise la méthode AddStyleAttribute pour affecter à l’attribut Color la valeur purple.If a Color style attribute is rendered, but the Color value is not purple, the OnStyleAttributeRender override uses the AddStyleAttribute method to set the Color attribute to 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

Remarks

L’implémentation de la classe HtmlTextWriter de la méthode OnStyleAttributeRender retourne toujours true.The HtmlTextWriter class implementation of the OnStyleAttributeRender method always returns true. Les remplacements OnStyleAttributeRender peuvent déterminer si un attribut de style sera rendu sur la page.The OnStyleAttributeRender overrides can determine whether a style attribute will be rendered to the page.

Notes to Inheritors

Si vous héritez de la classe HtmlTextWriter, vous pouvez substituer la méthode OnStyleAttributeRender(String, String, HtmlTextWriterStyle) pour retourner false pour empêcher un attribut de style d’être rendu, rendu sur un élément particulier ou rendu pour un langage de balisage particulier.If you inherit from the HtmlTextWriter class, you can override the OnStyleAttributeRender(String, String, HtmlTextWriterStyle) method to return false to prevent a style attribute from being rendered at all, being rendered on a particular element, or being rendered for a particular markup language. Par exemple, si vous ne souhaitez pas que l’objet dérivé de HtmlTextWriter restitue l’attribut de style color à un élément <p>, vous pouvez substituer la OnStyleAttributeRender(String, String, HtmlTextWriterStyle) et retourner false lorsque name passe color et que la valeur de la propriété TagName est p.For example, if you do not want the object that is derived from HtmlTextWriter to render the color style attribute to a <p> element, you can override the OnStyleAttributeRender(String, String, HtmlTextWriterStyle) and return false when name passes color and the TagName property value is p.

Applies to

See also