HtmlTextWriter.OnAttributeRender 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 marcado especificado y su valor se pueden representar en el elemento de marcado actual.
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
Parámetros
- name
- String
Cadena que contiene el nombre del atributo que se va a representar.
- value
- String
Cadena que contiene el valor asignado al atributo .
HtmlTextWriterAttribute Asociado al atributo de marcado.
Devoluciones
Siempre true.
Ejemplos
En el ejemplo de código siguiente se muestra cómo invalidar el OnAttributeRender método . Si se representa un Size atributo, pero el Size valor no 30ptes , la OnAttributeRender invalidación llama al AddAttribute método para agregar un Size atributo y establecer su valor en 30pt.
// 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
Comentarios
La HtmlTextWriter implementación de clase del OnAttributeRender método siempre devuelve true. Las OnAttributeRender invalidaciones pueden determinar si un atributo se representará en la página.
Notas a los desarrolladores de herederos
Si hereda de la HtmlTextWriter clase , puede invalidar el OnAttributeRender(String, String, HtmlTextWriterAttribute) método para devolver false para evitar que un atributo se represente en absoluto, que se represente en un elemento determinado o que se represente para un marcado determinado. Por ejemplo, si no desea que el objeto derivado de represente el HtmlTextWriter atributo en bgcolor elementos, puede invalidar <table> y devolver OnAttributeRender(String, String, HtmlTextWriterAttribute) cuando false se pasa name y el valor de la bgcolor propiedad es TagName.table