HtmlTextWriter.TagName 属性

定义

获取或设置所呈现的标记元素的标记名称。

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>如果元素即将呈现,则元素的<font>开始标记(属性color设置为 red)将呈现在<label>元素的开始标记之前。 如果要呈现的元素不是 <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属性;这是唯一将其设置为一致值的时间。

适用于

另请参阅