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 寫會緊接在元素之前 <label> 插入專案的開頭標記 <font> 。 如果未轉譯 <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 會很有用。

給繼承者的注意事項

方法 HtmlTextWriter 的類別實作 RenderBeforeTag() 會傳 null 回 。 如果您想要在專案開頭標記前面寫入文字或間距,請覆寫 RenderBeforeTag()

適用於

另請參閱