HtmlTextWriter.OnTagRender(String, HtmlTextWriterTag) Método

Definição

Determina se o elemento de marcação especificado será renderizado para a página solicitante.Determines whether the specified markup element will be rendered to the requesting page.

protected:
 virtual bool OnTagRender(System::String ^ name, System::Web::UI::HtmlTextWriterTag key);
protected virtual bool OnTagRender (string name, System.Web.UI.HtmlTextWriterTag key);
abstract member OnTagRender : string * System.Web.UI.HtmlTextWriterTag -> bool
override this.OnTagRender : string * System.Web.UI.HtmlTextWriterTag -> bool
Protected Overridable Function OnTagRender (name As String, key As HtmlTextWriterTag) As Boolean

Parâmetros

name
String

Uma cadeia de caracteres que contém o nome do elemento a renderizar.A string containing the name of the element to render.

key
HtmlTextWriterTag

O HtmlTextWriterTag associado ao elemento.The HtmlTextWriterTag associated with the element.

Retornos

Boolean

Sempre true.Always true.

Exemplos

O exemplo de código a seguir mostra como substituir o OnTagRender método.The following code example shows how to override the OnTagRender method. Se um Font elemento estiver sendo renderizado, a OnTagRender substituição usará o IsAttributeDefined método para determinar se um Size atributo está sendo renderizado.If a Font element is being rendered, the OnTagRender override uses the IsAttributeDefined method to determine whether a Size attribute is being rendered. Caso contrário, ele usa o AddAttribute método para criar um Size atributo e definir seu valor como 20pt .If not, it uses the AddAttribute method to create a Size attribute and set its value to 20pt.

// If a <font> element is to be rendered, check whether it contains
// a size attribute. If it does not, add one and set its value to
// 20 points, then return true.
protected override bool OnTagRender(string name, HtmlTextWriterTag key)
{

    if (key == HtmlTextWriterTag.Font)
    {
        if (!(IsAttributeDefined(HtmlTextWriterAttribute.Size)))
        {
            AddAttribute(HtmlTextWriterAttribute.Size, "20pt");
            return true;
        }
    }

    // If the element is not a <font> element, use
    // the base functionality of the OnTagRenderMethod.
    return base.OnTagRender(name, key);
}
' If a <font> element is to be rendered, check whether it contains
' a size attribute. If it does not, add one and set its value to
' 20 points, then return true.
Protected Overrides Function OnTagRender( _
    name As String, _
    key As HtmlTextWriterTag) _
As Boolean

    If (key = HtmlTextWriterTag.Font) Then
        If Not (IsAttributeDefined(HtmlTextWriterAttribute.Size)) Then
            AddAttribute(HtmlTextWriterAttribute.Size, "20pt")
            Return True
        End If
    End If

    ' If the element is not a <font> element, use
    ' the base functionality of the OnTagRenderMethod.
    Return MyBase.OnTagRender(name, key)
End Function

Comentários

A HtmlTextWriter implementação de classe do OnTagRender método sempre retorna true .The HtmlTextWriter class implementation of the OnTagRender method always returns true. As OnTagRender substituições podem determinar se um elemento será renderizado para a página.The OnTagRender overrides can determine whether an element will be rendered to the page.

Notas aos Herdeiros

Se você herdar da HtmlTextWriter classe, poderá substituir o OnTagRender(String, HtmlTextWriterTag) método a ser retornado false para impedir que um elemento de marcação seja renderizado ou para uma linguagem de marcação específica.If you inherit from the HtmlTextWriter class, you can override the OnTagRender(String, HtmlTextWriterTag) method to return false to prevent a markup element from being rendered at all or for a particular markup language. Por exemplo, se você não quiser o objeto derivado de HtmlTextWriter para renderizar o <font> elemento, poderá substituir o OnTagRender(String, HtmlTextWriterTag) método para retornar false quando for solicitada uma página que contenha um <font> elemento.For example, if you do not want the object that is derived from HtmlTextWriter to render the <font> element, you can override the OnTagRender(String, HtmlTextWriterTag) method to return false when a page is requested that contains a <font> element.

Aplica-se a

Confira também