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 di 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.
Valori restituiti
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 Color valore non purpleè , l'override OnStyleAttributeRender usa il AddStyleAttribute metodo per impostare l'attributo Color 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 . Le OnStyleAttributeRender sostituzioni possono determinare se nella pagina verrà eseguito il rendering di un attributo di stile.
Note per gli eredi
Se si eredita dalla HtmlTextWriter classe , è possibile eseguire l'override del metodo per evitare OnStyleAttributeRender(String, String, HtmlTextWriterStyle) che venga eseguito il rendering di un attributo di stile, di cui viene eseguito il rendering su un particolare elemento o di cui viene eseguito il false rendering per un particolare linguaggio di markup. Ad esempio, se non si desidera che l'oggetto derivato da HtmlTextWriter per eseguire il rendering dell'attributo di stile in un color elemento , è possibile eseguire l'override <p> di OnStyleAttributeRender(String, String, HtmlTextWriterStyle) e restituire false quando name passa color e il valore della TagName proprietà è p.