HtmlTextWriter.RenderBeforeTag Metoda

Definicja

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

C#
protected virtual string RenderBeforeTag();

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 .

C#
// 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();
    }
}

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

Produkt Wersje
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

Zobacz też