HtmlTextWriter.RenderBeforeTag Method

Definition

Schreibt Text oder Abstände vor dem Starttag eines Markupelements.Writes any text or spacing that occurs before the opening tag of a markup element.

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

Returns

String

Der Text oder Abstand, der vor dem Starttag des Markupelements geschrieben werden soll.The text or spacing to write before the markup element opening tag. null, wenn die Methode nicht überschrieben wurde.If not overridden, null.

Examples

Im folgenden Codebeispiel wird gezeigt, wie die RenderBeforeTag-Methode überschrieben wird, um zu bestimmen, ob eine von der HtmlTextWriter-Klasse abgeleitete Klasse im Begriff ist, ein <label>-Element zu Rendering.The following code example shows how to override the RenderBeforeTag method to determine whether a class that is derived from the HtmlTextWriter class is about to render a <label> element. Wenn dies der Fall ist, fügt die RenderBeforeTag Überschreibung das öffnende Tag eines <font> Elements direkt vor dem <label> Element ein.If so, the RenderBeforeTag override inserts the opening tag of a <font> element immediately before the <label> element. Wenn kein <label> Element gerendert wird, wird die RenderBeforeTag Basis Methode verwendet.If it is not rendering a <label> element, the RenderBeforeTag base method is used.

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

Remarks

Die RenderBeforeTag-Methode kann nützlich sein, wenn Sie zusätzliche öffnende Tags vor dem öffnenden Tag des vorgesehenen Elements Rendering möchten.The RenderBeforeTag method can be useful if you want to render additional opening tags before the opening tag of the intended element.

Notes to Inheritors

Die HtmlTextWriter-Klassen Implementierung der RenderBeforeTag()-Methode gibt nullzurück.The HtmlTextWriter class implementation of the RenderBeforeTag() method returns null. Überschreiben Sie RenderBeforeTag(), wenn Sie Text oder Abstände vor dem Starttag des Elements schreiben möchten.Override RenderBeforeTag() if you want to write text or spacing ahead of the element opening tag.

Applies to

See also