HtmlTextWriter.TagName Vlastnost

Definice

Získá nebo nastaví název značky vykreslovaného prvku značky.

protected:
 property System::String ^ TagName { System::String ^ get(); void set(System::String ^ value); };
protected string TagName { get; set; }
member this.TagName : string with get, set
Protected Property TagName As String

Hodnota vlastnosti

String

Název značky vykreslovaného prvku značky.

Příklady

Následující příklad kódu ukazuje přepsánou verzi RenderBeforeTag metody ve třídě, která je odvozena z HtmlTextWriter třídy. Příklad kódu zkontroluje, zda je prvek vykreslený <label> element voláním String.Compare metody a následným předáním TagName hodnoty vlastnosti a řetězce , "label"jako argumenty parametru. <label> Pokud se má prvek vykreslit, otevře se značka elementu <font> s atributem color nastaveným na red, před počáteční značkou elementu<label>. Pokud element, který se má vykreslit, není <label> element, volá se verze RenderBeforeTag základní třídy metody.

// Override the RenderBeforeTag method to add the
// opening tag of a Font element before the
// opening tag of any Label elements rendered by this
// custom markup writer.
virtual String^ RenderBeforeTag() override
{
   // Compare the TagName property value to the
   // String* label to determine whether the element to
   // be rendered is a Label. If it is a Label,
   // the opening tag of the Font element, with a Color
   // style attribute set to red, is added before
   // the Label.
   if ( String::Compare( TagName, "label" ) == 0 )
   {
      return "<font color=\"red\">";
   }
   // If a Label is not being rendered, use
   // the base RenderBeforeTag method.
   else
   {
      return __super::RenderBeforeTag();
   }
}
// Override the RenderBeforeTag method to add the 
// opening tag of a Font element before the 
// opening tag of any Label elements rendered by this 
// custom markup writer. 
protected override string RenderBeforeTag()
{
    // Compare the TagName property value to the
    // string label to determine whether the element to 
    // be rendered is a Label. If it is a Label,
    // the opening tag of the Font element, with a Color
    // style attribute set to red, is added before
    // the Label.
    if (String.Compare(TagName, "label") == 0)
    {
        return "<font color=\"red\">";
    }
    // If a Label is not being rendered, use 
        // the base RenderBeforeTag method.
    else
    {
        return base.RenderBeforeTag();
    }
}
' Override the RenderBeforeTag method to add the 
' opening tag of a Font element before the 
' opening tag of any Label elements rendered by this 
' custom markup writer. 
Protected Overrides Function RenderBeforeTag() As String
    ' Compare the TagName property value to the
    ' string label to determine whether the element to 
    ' be rendered is a Label. If it is a Label,
    ' the opening tag of the Font element, with a Color
    ' style attribute set to red, is added before
    ' the Label.
    If String.Compare(TagName, "label") = 0 Then
        Return "<font color=""red"">"
        ' If a Label is not being rendered, use 
        ' the base RenderBeforeTag method.
    Else
        Return MyBase.RenderBeforeTag()
    End If
End Function 'RenderBeforeTag

Poznámky

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

Platí pro

Viz také