HtmlTextWriter.TagKey Propriedade

Definição

Obtém ou define o valor HtmlTextWriterTag para o 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 da propriedade

HtmlTextWriterTag

O elemento de marcação que está tendo sua marca de abertura renderizada.

Exceções

O valor da propriedade não pode ser definido.

Exemplos

O exemplo de código a seguir demonstra uma versão substituída do RenderBeforeContent método em uma classe derivada da HtmlTextWriter classe. Ele usa o valor da TagKey propriedade para determinar se um controle de servidor usando o objeto personalizado HtmlTextWriter está renderizando um <label> elemento de marcação. Se for, um <font> elemento com um color conjunto de atributos a red ser retornado 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

Comentários

A TagKey propriedade é usada apenas para classes que herdam da HtmlTextWriter classe. Você deve ler ou definir a TagKey propriedade somente em uma chamada para o RenderBeginTag método; esta é a única vez que ela é definida como um valor consistente.

Aplica-se a

Confira também