HtmlTextWriter.OnStyleAttributeRender Metodo
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Determina se è possibile eseguire il rendering dell'attributo di stile markup specificato e del relativo valore nell'elemento di markup corrente.
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
Parametri
- name
- String
Stringa contenente il nome dell'attributo di stile di cui eseguire il rendering.
- value
- String
Stringa contenente il valore assegnato all'attributo di stile.
Oggetto HtmlTextWriterStyle associato all'attributo di stile.
Restituisce
Sempre true.
Esempio
Nell'esempio di codice seguente viene illustrato come eseguire l'override del OnStyleAttributeRender metodo. Se viene eseguito il rendering di un Color attributo di stile, ma il valore non purpleè , l'override ColorOnStyleAttributeRender usa il metodo per impostare l'attributo AddStyleAttributeColor su 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
Commenti
L'implementazione HtmlTextWriter della classe del OnStyleAttributeRender metodo restituisce truesempre . Gli OnStyleAttributeRender overridi possono determinare se verrà eseguito il rendering di un attributo di stile alla pagina.
Note per gli eredi
Se si eredita dalla classe, è possibile eseguire l'override del HtmlTextWriterOnStyleAttributeRender(String, String, HtmlTextWriterStyle) metodo per restituire false per impedire il rendering di un attributo di stile, il rendering su un elemento specifico o il rendering per un determinato linguaggio di markup. Ad esempio, se non si vuole che l'oggetto derivato da HtmlTextWriter per eseguire il rendering dell'attributo di stile a un <p> elemento, è possibile eseguire l'override color e OnStyleAttributeRender(String, String, HtmlTextWriterStyle) restituire false quando name passa color e il valore della TagName proprietà è p.