HtmlTextWriter.OnStyleAttributeRender Método
Definición
Importante
Parte de la información hace referencia a la versión preliminar del producto, que puede haberse modificado sustancialmente antes de lanzar la versión definitiva. Microsoft no otorga ninguna garantía, explícita o implícita, con respecto a la información proporcionada aquí.
Determina si el atributo de estilo de marcado especificado y su valor se pueden representar en el elemento de marcado actual.
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
Parámetros
- name
- String
Cadena que contiene el nombre del atributo de estilo que se va a representar.
- value
- String
Cadena que contiene el valor asignado al atributo style.
HtmlTextWriterStyle asociado al atributo style.
Devoluciones
Siempre true.
Ejemplos
En el ejemplo de código siguiente se muestra cómo invalidar el OnStyleAttributeRender método . Si se representa un Color atributo de estilo, pero el Color valor no purplees , la OnStyleAttributeRender invalidación usa el AddStyleAttribute método para establecer el Color atributo purpleen .
// 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
Comentarios
La HtmlTextWriter implementación de clase del OnStyleAttributeRender método siempre devuelve true. Las OnStyleAttributeRender invalidaciones pueden determinar si se representará un atributo de estilo en la página.
Notas a los desarrolladores de herederos
Si hereda de la HtmlTextWriter clase , puede invalidar el OnStyleAttributeRender(String, String, HtmlTextWriterStyle) método para devolver false para evitar que un atributo de estilo se represente en absoluto, que se represente en un elemento determinado o que se represente para un lenguaje de marcado determinado. Por ejemplo, si no desea que el objeto derivado de represente el HtmlTextWriter atributo style en un color elemento, puede invalidar <p> y devolver OnStyleAttributeRender(String, String, HtmlTextWriterStyle) cuando false se pasa name y el valor de la color propiedad es TagName.p