Sdílet prostřednictvím


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

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

Příklady

Následující příklad kódu ukazuje přepsání verze RenderBeforeTag metody ve třídě, která je odvozena z HtmlTextWriter třídy. Příklad kódu zkontroluje, zda element, který se má vykreslit, <label> voláním String.Compare metody a předáním TagName hodnoty vlastnosti a řetězce , "label"jako argumenty parametru. Pokud se <label> má prvek vykreslit, je počáteční značka <font> elementu s atributem nastaveným color na red, vykreslena před <label> počáteční značkou elementu. Pokud element, který se má vykreslit, není <label> prvek, je volána 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 je používána pouze pro třídy, které dědí z HtmlTextWriter třídy. Vlastnost byste měli číst nebo nastavovat TagName pouze ve RenderBeginTag volání metody. Je to jediný čas, kdy je nastavena na konzistentní hodnotu.

Platí pro

Viz také