HtmlTextWriter.TagName Proprietà

Definizione

Ottiene o imposta il nome del tag dell'elemento di markup di cui eseguire il rendering.

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

Valore della proprietà

String

Nome del tag dell'elemento di markup di cui eseguire il rendering.

Esempio

Nell'esempio RenderBeforeTag di codice seguente viene illustrata una versione sottoposto a override del metodo in una classe che deriva dalla HtmlTextWriter classe . L'esempio di codice verifica se l'elemento da eseguire è un <label> elemento chiamando il metodo e quindi passando il String.Compare valore della TagName proprietà e una stringa, , "label"come argomenti dei parametri. Se un <label> elemento sta per essere eseguito il rendering, il tag di apertura di un <font> elemento, con un color attributo impostato su red, viene eseguito il rendering prima <label> del tag di apertura dell'elemento. Se l'elemento da eseguire il rendering non è un <label> elemento, viene chiamata la versione della classe base del RenderBeforeTag metodo.

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

Commenti

La TagName proprietà è di uso solo per le classi che ereditano dalla HtmlTextWriter classe. È necessario leggere o impostare la proprietà solo nelle RenderBeginTag chiamate al metodo. Questa è l'unica TagName volta che è impostata su un valore coerente.

Si applica a

Vedi anche