HtmlTextWriter.TagKey Propriedade

Definição

Obtém ou define o HtmlTextWriterTag valor do elemento de marcação especificado.

protected:
 property System::Web::UI::HtmlTextWriterTag TagKey { System::Web::UI::HtmlTextWriterTag get(); void set(System::Web::UI::HtmlTextWriterTag value); };
protected System.Web.UI.HtmlTextWriterTag TagKey { get; set; }
member this.TagKey : System.Web.UI.HtmlTextWriterTag with get, set
Protected Property TagKey As HtmlTextWriterTag

Valor de Propriedade

O elemento de marcação que está a ter a etiqueta de abertura renderizada.

Exceções

O valor da propriedade não pode ser definido.

Exemplos

O seguinte exemplo de código demonstra uma versão sobreposta do RenderBeforeContent método numa classe que deriva da HtmlTextWriter classe. Utiliza o valor da TagKey propriedade para determinar se um controlo de servidor que utiliza o objeto personalizado HtmlTextWriter está a renderizar um <label> elemento de marcação. Se estiver, um <font> elemento com um color atributo definido como red é devolvido para modificar a formatação do <label> texto do elemento.

// Override the RenderBeforeContent method to write
// a font element that applies red to the text in a Label element.

virtual String^ RenderBeforeContent() override
{
   
   // Check to determine whether the element being rendered
   // is a label element. If so, render the opening tag
   // of the font element; otherwise, call the base method.
   if ( TagKey == HtmlTextWriterTag::Label )
   {
      return "<font color=\"red\">";
   }
   else
   {
      return __super::RenderBeforeContent();
   }
}
// Override the RenderBeforeContent method to write
// a font element that applies red to the text in a Label element.
protected override string RenderBeforeContent()
{
    // Check to determine whether the element being rendered
    // is a label element. If so, render the opening tag
    // of the font element; otherwise, call the base method.
    if (TagKey == HtmlTextWriterTag.Label)
    {
        return "<font color=\"red\">";
    }
    else
    {
        return base.RenderBeforeContent();
    }
}
' Override the RenderBeforeContent method to write
' a font element that applies red to the text in a Label element.
Protected Overrides Function RenderBeforeContent() As String
    ' Check to determine whether the element being rendered
    ' is a label element. If so, render the opening tag
    ' of the font element; otherwise, call the base method.
    If TagKey = HtmlTextWriterTag.Label Then
        Return "<font color=""red"">"
    Else
        Return MyBase.RenderBeforeContent()
    End If
End Function 'RenderBeforeContent

Observações

A TagKey propriedade é útil apenas para classes que herdam da HtmlTextWriter classe. Deve ler ou definir a TagKey propriedade apenas numa chamada ao RenderBeginTag método; esta é a única vez que é definida para um valor consistente.

Aplica-se a

Ver também