HtmlTextWriter.OnStyleAttributeRender Méthode
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Détermine si l’attribut de style de balisage spécifié et sa valeur peuvent être restitués à l’élément de balisage actuel.
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
Paramètres
- name
- String
Chaîne contenant le nom de l’attribut de style à afficher.
- value
- String
Chaîne contenant la valeur affectée à l’attribut de style.
Associé HtmlTextWriterStyle à l’attribut de style.
Retours
A toujours la valeur true.
Exemples
L’exemple de code suivant montre comment remplacer la OnStyleAttributeRender méthode. Si un Color attribut de style est rendu, mais que la Color valeur n’est pas purple, le OnStyleAttributeRender remplacement utilise la AddStyleAttribute méthode pour définir l’attribut Colorpurplesur .
// 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
Remarques
L’implémentation HtmlTextWriter de classe de la OnStyleAttributeRender méthode retourne truetoujours . Les OnStyleAttributeRender remplacements peuvent déterminer si un attribut de style sera rendu sur la page.
Notes pour les héritiers
Si vous héritez de la HtmlTextWriter classe, vous pouvez remplacer la OnStyleAttributeRender(String, String, HtmlTextWriterStyle) méthode pour false empêcher le rendu d’un attribut de style, le rendu sur un élément particulier ou le rendu d’un langage de balisage particulier. Par exemple, si vous ne souhaitez pas que l’objet dérivé d’un HtmlTextWriter élément affiche l’attribut color de style sur un <p> élément, vous pouvez remplacer et OnStyleAttributeRender(String, String, HtmlTextWriterStyle) retourner false le moment où name il passe color et la valeur de la TagName propriété est p.