HtmlTextWriter.RenderBeforeContent Metoda

Definicja

Zapisuje dowolny tekst lub odstępy przed zawartością i po tagu otwierania elementu znaczników.

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

Zwraca

String

Tekst lub odstępy do zapisania przed zawartością elementu. Jeśli nie zostanie zastąpiona, RenderBeforeContent() zwraca wartość null.

Przykłady

W poniższym przykładzie kodu pokazano, jak zastąpić metodę RenderBeforeContent w celu określenia, czy klasa pochodna klasy ma HtmlTextWriter renderować <label> element. Jeśli tak, RenderBeforeContent przesłonięcia wstawia tag <font> otwierający elementu bezpośrednio po otwarciu tagu <label> elementu. Jeśli nie <label> jest to element, zostanie użyta metoda podstawowa RenderBeforeContent .

// Override the RenderBeforeContent method to write
// a font element that applies red to the text in a Label element.

virtual String^ RenderBeforeContent() override
{
   
   // Check to determine whether the element being rendered
   // is a label element. If so, render the opening tag
   // of the font element; otherwise, call the base method.
   if ( TagKey == HtmlTextWriterTag::Label )
   {
      return "<font color=\"red\">";
   }
   else
   {
      return __super::RenderBeforeContent();
   }
}
// Override the RenderBeforeContent method to write
// a font element that applies red to the text in a Label element.
protected override string RenderBeforeContent()
{
    // Check to determine whether the element being rendered
    // is a label element. If so, render the opening tag
    // of the font element; otherwise, call the base method.
    if (TagKey == HtmlTextWriterTag.Label)
    {
        return "<font color=\"red\">";
    }
    else
    {
        return base.RenderBeforeContent();
    }
}
' Override the RenderBeforeContent method to write
' a font element that applies red to the text in a Label element.
Protected Overrides Function RenderBeforeContent() As String
    ' Check to determine whether the element being rendered
    ' is a label element. If so, render the opening tag
    ' of the font element; otherwise, call the base method.
    If TagKey = HtmlTextWriterTag.Label Then
        Return "<font color=""red"">"
    Else
        Return MyBase.RenderBeforeContent()
    End If
End Function 'RenderBeforeContent

Uwagi

Metoda może być przydatna RenderBeforeContent , jeśli chcesz wstawić elementy podrzędne do bieżącego elementu znaczników przed wewnętrznym znacznikami.

Uwagi dotyczące dziedziczenia

Implementacja HtmlTextWriter RenderBeforeContent() klasy metody zwraca wartość null. Zastąpij RenderBeforeContent() , jeśli chcesz napisać tekst lub odstępy po tagu otwierania, ale przed zawartością elementu.

Dotyczy

Zobacz też