Share via


HtmlTextWriter.RenderBeforeTag Método

Definición

Escribe el espaciado o texto que aparece delante de la etiqueta de apertura de un elemento de marcado.

protected:
 virtual System::String ^ RenderBeforeTag();
protected virtual string RenderBeforeTag ();
abstract member RenderBeforeTag : unit -> string
override this.RenderBeforeTag : unit -> string
Protected Overridable Function RenderBeforeTag () As String

Devoluciones

String

Espaciado o texto que se va a escribir delante de la etiqueta de apertura del elemento. Si no se reemplaza, null.

Ejemplos

En el ejemplo de código siguiente se muestra cómo invalidar el RenderBeforeTag método para determinar si una clase derivada de la HtmlTextWriter clase está a punto de representar un <label> elemento. Si es así, la RenderBeforeTag invalidación inserta la etiqueta de apertura de un <font> elemento inmediatamente antes del <label> elemento . Si no representa un <label> elemento, se usa el RenderBeforeTag método base.

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

El RenderBeforeTag método puede ser útil si desea representar etiquetas de apertura adicionales antes de la etiqueta de apertura del elemento previsto.

Notas a los desarrolladores de herederos

La HtmlTextWriter implementación de clase del RenderBeforeTag() método devuelve null. Invalide RenderBeforeTag() si desea escribir texto o espaciado delante de la etiqueta de apertura de elementos.

Se aplica a

Consulte también