HtmlTextWriter.TagName 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定所呈現的標記項目的標記名稱。
protected:
property System::String ^ TagName { System::String ^ get(); void set(System::String ^ value); };
protected string TagName { get; set; }
member this.TagName : string with get, set
Protected Property TagName As String
屬性值
所呈現的標記項目的標記名稱。
範例
下列程式碼範例示範衍生自 HtmlTextWriter 類別中方法的 RenderBeforeTag 覆寫版本。 程式碼範例會藉由呼叫 String.Compare 方法來檢查要呈現的專案是否為 <label>
專案,然後傳遞 TagName 屬性值和字串 "label"
作為參數引數。 <label>
如果專案即將轉譯,則會在元素的開頭標記之前 <label>
轉譯元素的開頭標記 <font>
,並將 color
屬性設定 red
為 。 如果要轉譯的專案不是 <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
備註
屬性 TagName 只用于繼承自 類別的 HtmlTextWriter 類別。 您應該只在方法呼叫中 RenderBeginTag 讀取或設定 TagName 屬性;這是它設定為一致值的唯一時間。