HtmlTextWriter.OnAttributeRender 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 balisage spécifié et sa valeur peuvent être rendus sur l’élément de balisage actuel.
protected:
virtual bool OnAttributeRender(System::String ^ name, System::String ^ value, System::Web::UI::HtmlTextWriterAttribute key);
protected virtual bool OnAttributeRender(string name, string value, System.Web.UI.HtmlTextWriterAttribute key);
abstract member OnAttributeRender : string * string * System.Web.UI.HtmlTextWriterAttribute -> bool
override this.OnAttributeRender : string * string * System.Web.UI.HtmlTextWriterAttribute -> bool
Protected Overridable Function OnAttributeRender (name As String, value As String, key As HtmlTextWriterAttribute) As Boolean
Paramètres
- name
- String
Chaîne contenant le nom de l’attribut à afficher.
- value
- String
Chaîne contenant la valeur affectée à l’attribut.
Associé HtmlTextWriterAttribute à l’attribut de balisage.
Retours
A toujours la valeur true.
Exemples
L’exemple de code suivant montre comment remplacer la OnAttributeRender méthode. Si un Size attribut est rendu, mais que la Size valeur n’est pas 30pt, le OnAttributeRender remplacement appelle la AddAttribute méthode pour ajouter un Size attribut et définir sa valeur 30ptsur .
// If a size attribute is to be rendered, compare its value to 30 point.
// If it is not set to 30 point, add the attribute and set the value to 30,
// then return false.
protected override bool OnAttributeRender(string name,
string value,
HtmlTextWriterAttribute key)
{
if (key == HtmlTextWriterAttribute.Size)
{
if (string.Compare(value, "30pt") != 0)
{
AddAttribute("size", "30pt");
return false;
}
}
// If the attribute is not a size attribute, use
// the base functionality of the OnAttributeRender method.
return base.OnAttributeRender(name, value, key);
}
' If a size attribute is to be rendered, compare its value to 30 point.
' If it is not set to 30 point, add the attribute and set the value to 30
' then return false.
Protected Overrides Function OnAttributeRender(name As String, _
value As String, _
key As HtmlTextWriterAttribute) _
As Boolean
If key = HtmlTextWriterAttribute.Size Then
If [String].Compare(value, "30pt") <> 0 Then
AddAttribute("size", "30pt")
Return False
End If
End If
' If the attribute is not a size attribute, use
' the base functionality of the OnAttributeRender method.
Return MyBase.OnAttributeRender(name, value, key)
End Function 'OnAttributeRender
Remarques
L’implémentation HtmlTextWriter de classe de la OnAttributeRender méthode retourne truetoujours . Les OnAttributeRender remplacements peuvent déterminer si un attribut sera rendu sur la page.
Notes pour les héritiers
Si vous héritez de la HtmlTextWriter classe, vous pouvez remplacer la OnAttributeRender(String, String, HtmlTextWriterAttribute) méthode pour false empêcher le rendu d’un attribut, le rendu sur un élément particulier ou le rendu d’un balisage particulier. Par exemple, si vous ne souhaitez pas que l’objet dérivé d’un HtmlTextWriter rendu de l’attribut bgcolor aux <table> éléments soit rendu, vous pouvez remplacer et OnAttributeRender(String, String, HtmlTextWriterAttribute) retourner false le moment où name il passe bgcolor et que la valeur de la TagName propriété est table.