HtmlTextWriter.OnAttributeRender Método

Definição

Determina se o atributo de marcação especificado e o seu valor podem ser representados no elemento de marcação atual.

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

Uma cadeia contendo o nome do atributo a renderizar.

value
String

Uma cadeia contendo o valor atribuído ao atributo.

key
HtmlTextWriterAttribute

O HtmlTextWriterAttribute associado ao atributo de marcação.

Devoluções

Sempre true.

Exemplos

O seguinte exemplo de código mostra como sobrescrever o OnAttributeRender método. Se um Size atributo for renderizado, mas o Size valor não 30ptfor , o OnAttributeRender override chama o AddAttribute método para adicionar um Size atributo e definir o seu valor para 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

Observações

A HtmlTextWriter implementação de classes do OnAttributeRender método devolve truesempre . Os OnAttributeRender overrides podem determinar se um atributo será renderizado na página.

Notas para Herdeiros

Se herdar da HtmlTextWriter classe, pode sobrepor o OnAttributeRender(String, String, HtmlTextWriterAttribute) método para regressar false e impedir que um atributo seja renderizado, seja renderizado num determinado elemento ou seja renderizado para uma marcação específica. Por exemplo, se não quiser que o objeto derivado de renderize o HtmlTextWriter atributo para bgcolor elementos, pode sobrescrever o <table> and return OnAttributeRender(String, String, HtmlTextWriterAttribute) quando false passa name e o bgcolor valor da propriedade é TagName.table

Aplica-se a

Ver também