HtmlTextWriter.GetStyleName(HtmlTextWriterStyle) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取与指定 HtmlTextWriterStyle 枚举值关联的标记样式属性名称。
protected:
System::String ^ GetStyleName(System::Web::UI::HtmlTextWriterStyle styleKey);
protected string GetStyleName(System.Web.UI.HtmlTextWriterStyle styleKey);
member this.GetStyleName : System.Web.UI.HtmlTextWriterStyle -> string
Protected Function GetStyleName (styleKey As HtmlTextWriterStyle) As String
参数
- styleKey
- HtmlTextWriterStyle
要 HtmlTextWriterStyle 获取其样式属性名称。
返回
与枚举HtmlTextWriterStyle值关联的styleKey样式属性名称。
示例
下面的代码示例演示如何检查 <label> 是否正在呈现元素。 如果是这样,它将检查 Color 是否已在元素上定义样式属性。 如果未定义该属性, AddStyleAttribute 将调用该方法,并且 GetStyleName 该方法将 Color 枚举成员转换为其字符串表示形式,以传递给 AddStyleAttribute 该方法。
// If the markup element being rendered is a Label,
// render the opening tag of a <Font> element before it.
if ( tagKey == HtmlTextWriterTag::Label )
{
// Check whether a Color style attribute is
// included on the Label. If not, use the
// AddStyleAttribute and GetStyleName methods to add one
// and set its value to red.
if ( !IsStyleAttributeDefined( HtmlTextWriterStyle::Color ) )
{
AddStyleAttribute( GetStyleName( HtmlTextWriterStyle::Color ), "red" );
}
// If the markup element being rendered is a Label,
// render the opening tag of a Font element before it.
if (tagKey == HtmlTextWriterTag.Label)
{
// Check whether a Color style attribute is
// included on the Label. If not, use the
// AddStyleAttribute and GetStyleName methods to add one
// and set its value to red.
if (!IsStyleAttributeDefined(HtmlTextWriterStyle.Color))
{
AddStyleAttribute(GetStyleName(HtmlTextWriterStyle.Color), "red");
}
' If the markup element being rendered is a Label,
' render the opening tag of a Font element before it.
If tagKey = HtmlTextWriterTag.Label Then
' Check whether a Color style attribute is
' included on the Label. If not, use the
' AddStyleAttribute and GetStyleName methods to add one
' and set its value to red.
If Not IsStyleAttributeDefined(HtmlTextWriterStyle.Color) Then
AddStyleAttribute(GetStyleName(HtmlTextWriterStyle.Color), "red")
End If
注解
如果 styleKey 不是有效的 HtmlTextWriterStyle 对象,该方法 GetStyleName 将返回一个空字符串(“)。