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

属性值

其开始标记要被呈现的标记元素。

例外

无法设置属性值。

示例

下面的代码示例演示派生自 HtmlTextWriter 类的 RenderBeforeContent 类中方法的重写版本。 它使用 属性的值 TagKey 来确定使用自定义 HtmlTextWriter 对象的服务器控件是否正在呈现 <label> 标记元素。 如果为 ,<font>则返回属性设置为 red 的元素color以修改元素文本的格式<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 属性;这是唯一将其设置为一致值的时间。

适用于

另请参阅