HtmlTextWriter.RenderBeforeContent Método

Definição

Grava qualquer texto ou espaçamento antes do conteúdo e após a marca de abertura de um elemento de marcação.Writes any text or spacing before the content and after the opening tag of a markup element.

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

Retornos

String

O texto ou espaçamento a gravar antes do conteúdo do elemento.The text or spacing to write prior to the content of the element. Se não for substituído, RenderBeforeContent() retorna null.If not overridden, RenderBeforeContent() returns null.

Exemplos

O exemplo de código a seguir mostra como substituir o RenderBeforeContent método para determinar se uma classe derivada da HtmlTextWriter classe está prestes a renderizar um <label> elemento.The following code example shows how to override the RenderBeforeContent method to determine whether a class derived from the HtmlTextWriter class is about to render a <label> element. Nesse caso, a RenderBeforeContent substituição insere a marca de abertura de um <font> elemento imediatamente após a marca de abertura do <label> elemento.If so, the RenderBeforeContent override inserts the opening tag of a <font> element immediately after the opening tag of the <label> element. Se não for um <label> elemento, o RenderBeforeContent método base será usado.If it is not a <label> element, the RenderBeforeContent base method is used.

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

Comentários

O RenderBeforeContent método pode ser útil se você quiser inserir elementos filho no elemento de marcação atual antes da marcação interna.The RenderBeforeContent method can be useful if you want to insert child elements into the current markup element before the inner markup.

Notas aos Herdeiros

A HtmlTextWriter implementação da classe do RenderBeforeContent() método retorna null .The HtmlTextWriter class implementation of the RenderBeforeContent() method returns null. Substitua RenderBeforeContent() se você quiser escrever texto ou espaçamento após a marca de abertura, mas antes do conteúdo do elemento.Override RenderBeforeContent() if you want to write text or spacing after the opening tag but ahead of the element content.

Aplica-se a

Confira também