HtmlTextWriter.RenderBeforeContent 方法

定义

在标记元素的内容之前、开始标记之后写入任何文本或间距。

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

返回

在元素内容之前写入的文本或间距。 如果未重写,则 RenderBeforeContent() 返回 null

示例

下面的代码示例演示如何重写 方法, RenderBeforeContent 以确定派生自 类的 HtmlTextWriter 类是否要呈现 <label> 元素。 如果是这样,则 RenderBeforeContent 替代将紧接在元素的 <font> 开始标记之后插入元素的 <label> 开始标记。 如果它不是 <label> 元素,则 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

注解

RenderBeforeContent如果要在内部标记之前将子元素插入到当前标记元素中,方法可能很有用。

继承者说明

方法 HtmlTextWriterRenderBeforeContent() 类实现返回 null。 如果要在开始标记之后但在元素内容之前写入文本或间距,请重写 RenderBeforeContent()

适用于

另请参阅