HtmlTextWriter.TagKey Vlastnost

Definice

Získá nebo nastaví HtmlTextWriterTag hodnotu pro zadaný prvek značky.

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

Hodnota vlastnosti

HtmlTextWriterTag

Element značek, který má vykreslovanou levou značku.

Výjimky

Hodnotu vlastnosti nelze nastavit.

Příklady

Následující příklad kódu ukazuje přepsánou verzi RenderBeforeContent metody ve třídě, která je odvozena z HtmlTextWriter třídy. Používá hodnotu TagKey vlastnosti k určení, zda ovládací prvek serveru pomocí vlastního HtmlTextWriter objektu vykresluje <label> prvek revize. Pokud ano, vrátí se <font> prvek s atributem color nastaveným na red úpravu formátování <label> textu prvku.

// 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

Poznámky

Vlastnost TagKey se používá pouze pro třídy, které dědí z HtmlTextWriter třídy. Vlastnost byste měli přečíst nebo nastavit TagKey pouze při volání RenderBeginTag metody. Je to jediný čas, kdy je nastavena na konzistentní hodnotu.

Platí pro

Viz také