共用方式為


HtmlTextWriter.TagKey 屬性

定義

取得或設定指定標記項目的 HtmlTextWriterTag 值。

protected:
 property System::Web::UI::HtmlTextWriterTag TagKey { System::Web::UI::HtmlTextWriterTag get(); void set(System::Web::UI::HtmlTextWriterTag value); };
protected System.Web.UI.HtmlTextWriterTag TagKey { get; set; }
member this.TagKey : System.Web.UI.HtmlTextWriterTag with get, set
Protected Property TagKey As HtmlTextWriterTag

屬性值

HtmlTextWriterTag

可以呈現開頭標記的標記項目。

例外狀況

無法設定這個屬性值。

範例

下列程式碼範例示範衍生自 HtmlTextWriter 類別中方法的 RenderBeforeContent 覆寫版本。 它會使用 屬性的值 TagKey 來判斷使用自訂 HtmlTextWriter 物件的伺服器控制項是否正在轉 <label> 譯標記專案。 如果是, <font> color 則會傳回屬性設定 red 為 的專案,以修改元素文字的格式 <label> 設定。

// Override the RenderBeforeContent method to write
// a font element that applies red to the text in a Label element.

virtual String^ RenderBeforeContent() override
{
   
   // Check to determine whether the element being rendered
   // is a label element. If so, render the opening tag
   // of the font element; otherwise, call the base method.
   if ( TagKey == HtmlTextWriterTag::Label )
   {
      return "<font color=\"red\">";
   }
   else
   {
      return __super::RenderBeforeContent();
   }
}
// Override the RenderBeforeContent method to write
// a font element that applies red to the text in a Label element.
protected override string RenderBeforeContent()
{
    // Check to determine whether the element being rendered
    // is a label element. If so, render the opening tag
    // of the font element; otherwise, call the base method.
    if (TagKey == HtmlTextWriterTag.Label)
    {
        return "<font color=\"red\">";
    }
    else
    {
        return base.RenderBeforeContent();
    }
}
' Override the RenderBeforeContent method to write
' a font element that applies red to the text in a Label element.
Protected Overrides Function RenderBeforeContent() As String
    ' Check to determine whether the element being rendered
    ' is a label element. If so, render the opening tag
    ' of the font element; otherwise, call the base method.
    If TagKey = HtmlTextWriterTag.Label Then
        Return "<font color=""red"">"
    Else
        Return MyBase.RenderBeforeContent()
    End If
End Function 'RenderBeforeContent

備註

屬性 TagKey 只用于繼承自 類別的 HtmlTextWriter 類別。 您應該只在呼叫 RenderBeginTag 方法時讀取或設定 TagKey 屬性;這是設定為一致值的唯一時間。

適用於

另請參閱