HtmlTextWriter.RenderBeforeTag Metoda

Definicja

Zapisuje dowolny tekst lub odstępy występujące przed otwarciem tagu elementu znaczników.

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

Zwraca

Tekst lub odstępy do zapisania przed tagiem otwierania elementu znaczników. Jeśli nie zastąpisz, null.

Przykłady

W poniższym przykładzie kodu pokazano, jak zastąpić metodę w RenderBeforeTag celu określenia, czy klasa, która pochodzi z HtmlTextWriter klasy, ma renderować <label> element. Jeśli tak, RenderBeforeTag zastąpienie wstawia znacznik <font> otwierający elementu bezpośrednio przed elementem <label> . Jeśli element nie jest renderujący <label> , zostanie użyta metoda podstawowa 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.
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

Uwagi

Metoda może być przydatna RenderBeforeTag , jeśli chcesz renderować dodatkowe tagi otwierające przed otwarciem zamierzonego elementu.

Uwagi dotyczące dziedziczenia

Implementacja HtmlTextWriter klasy RenderBeforeTag() metody zwraca wartość null. Zastąpij RenderBeforeTag() , jeśli chcesz napisać tekst lub odstępy przed tagiem otwierania elementu.

Dotyczy

Zobacz też