HtmlTextWriter.RenderBeforeTag 方法

定义

写入在标记元素的开始标记之前出现的任何文本或间距。

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

返回

要在标记元素开始标记之前写入的文本或间距。 如果未重写,则为 null

示例

下面的代码示例演示如何重写 方法, RenderBeforeTag 以确定派生自 类 HtmlTextWriter 的类是否要呈现 <label> 元素。 如果是这样,重写会将 RenderBeforeTag 元素的 <font> 开始标记插入紧靠该元素的 <label> 前面。 如果未呈现 <label> 元素,则 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

注解

RenderBeforeTag如果要在预期元素的开始标记之前呈现其他开始标记,方法可能很有用。

继承者说明

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

适用于

另请参阅