HtmlTextWriter.RenderAfterContent 方法

定義

將標記項目的內容之後及結尾標記之前出現的任何文字或間距,寫入標記輸出資料流。

C#
protected virtual string RenderAfterContent();

傳回

字串,包含項目的內容之後所要寫入的間距或文字。

範例

下列程式碼範例示範如何覆寫 RenderAfterContent 衍生自 HtmlTextWriter 類別的 類別中的 方法,以判斷是否 <label> 要轉譯專案。 如果是的話,覆 RenderAfterContent 寫會 <font> 緊接在專案的結束記號之前插入專案的結束記號 <label> 。 如果要轉譯以外的 <label> 專案,則會 RenderAfterContent 使用基底方法。

C#
// Override the RenderAfterContent method to render
// the closing tag of a font element if the 
// rendered tag is a label element.
protected override string RenderAfterContent()
{
    // Check to determine whether the element being rendered
    // is a label element. If so, render the closing tag
    // of the font element; otherwise, call the base method.
    if (TagKey == HtmlTextWriterTag.Label)
    {
        return "</font>";
    }
    else
    {
        return base.RenderAfterContent();
    }
}

備註

如果您想要將子專案插入目前的標記專案,此方法 RenderAfterContent 會很有用。

給繼承者的注意事項

方法 HtmlTextWriter 的類別實作 RenderAfterContent() 會傳 null 回 。 如果您想要在專案內容之後,但在結束記號之前寫入文字或間距,請覆寫 RenderAfterContent()

適用於

產品 版本
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

另請參閱