HtmlTextWriter.TagName Propiedad

Definición

Obtiene o establece el nombre de etiqueta del elemento de marcado que se va a representar.

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

Valor de propiedad

String

Nombre de etiqueta del elemento de marcado que se va a representar.

Ejemplos

En el ejemplo de código siguiente se muestra una versión invalidada del RenderBeforeTag método en una clase que deriva de la HtmlTextWriter clase . El ejemplo de código comprueba si el elemento que se va a representar es un <label> elemento llamando al String.Compare método y, a continuación, pasando el TagName valor de propiedad y una cadena, "label", como argumentos de parámetro. Si un <label> elemento está a punto de representarse, la etiqueta de apertura de un <font> elemento, con un color atributo establecido reden , se representa antes de la <label> etiqueta de apertura del elemento. Si el elemento que se va a representar no es un <label> elemento, se llama a la versión de la clase base del RenderBeforeTag método .

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

Comentarios

La TagName propiedad es de uso solo para las clases que heredan de la HtmlTextWriter clase . Debe leer o establecer la TagName propiedad solo en RenderBeginTag las llamadas a métodos; es la única vez que se establece en un valor coherente.

Se aplica a

Consulte también