HtmlTextWriter.RenderAfterTag 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
寫入標記項目的結尾標記之後所發生的任何間距或文字。
protected:
virtual System::String ^ RenderAfterTag();
protected virtual string RenderAfterTag ();
abstract member RenderAfterTag : unit -> string
override this.RenderAfterTag : unit -> string
Protected Overridable Function RenderAfterTag () As String
傳回
要在項目的結尾標記之後寫入的間距或文字。
範例
下列程式碼範例示範如何覆寫 RenderAfterTag 方法,以判斷衍生自 類別的 HtmlTextWriter 類別是否呈現 <label>
專案。 如果是,覆 RenderAfterTag 寫會緊接在 元素後面 <label>
插入專案的 <font>
結束記號。 如果不是 <label>
元素,則會 RenderAfterTag 使用基底方法。
// Override the RenderAfterTag method to add the
// closing tag of the Font element after the
// closing tag of a Label element has been rendered.
virtual String^ RenderAfterTag() 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 closing tag of a Font element is rendered
// after the closing tag of the Label element.
if ( String::Compare( TagName, "label" ) == 0 )
{
return "</font>";
}
// If a Label is not being rendered, use
// the base RenderAfterTag method.
else
{
return __super::RenderAfterTag();
}
}
// Override the RenderAfterTag method to add the
// closing tag of the Font element after the
// closing tag of a Label element has been rendered.
protected override string RenderAfterTag()
{
// 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 closing tag of a Font element is rendered
// after the closing tag of the Label element.
if (String.Compare(TagName, "label") == 0)
{
return "</font>";
}
// If a Label is not being rendered, use
// the base RenderAfterTag method.
else
{
return base.RenderAfterTag();
}
}
' Override the RenderAfterTag method to add the
' closing tag of the Font element after the
' closing tag of a Label element has been rendered.
Protected Overrides Function RenderAfterTag() 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 closing tag of a Font element is rendered
' after the closing tag of the Label element.
If String.Compare(TagName, "label") = 0 Then
Return "</font>"
' If a Label is not being rendered, use
' the base RenderAfterTag method.
Else
Return MyBase.RenderAfterTag()
End If
End Function 'RenderAfterTag
End Class
備註
如果您想要在專案標籤之後轉譯其他結束記號,此方法 RenderAfterTag 會很有用。
給繼承者的注意事項
方法 HtmlTextWriter 的類別實作 RenderAfterTag() 會傳 null
回 。 如果您想要在專案結束記號後面寫入文字或間距,請覆寫 RenderAfterTag() 。