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
属性值
正在呈现的标记元素的标记名称。
示例
下面的代码示例演示从RenderBeforeTag类派生的类中重写的方法版本HtmlTextWriter。 代码示例通过调用<label>方法检查要呈现的元素是否为String.Compare元素,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 类。 应仅在方法调用中TagName读取或设置RenderBeginTag属性;这是唯一设置为一致值的时间。