Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

HtmlTextWriter.GetStyleName Method

Obtains the markup style attribute name associated with the specified HtmlTextWriterStyle enumeration value.

Namespace: System.Web.UI
Assembly: System.Web (in system.web.dll)
protected string GetStyleName (
	HtmlTextWriterStyle styleKey
)
protected String GetStyleName (
	HtmlTextWriterStyle styleKey
)
protected function GetStyleName (
	styleKey : HtmlTextWriterStyle
) : String
Not applicable.

Parameters

styleKey

The HtmlTextWriterStyle to obtain the style attribute name for.

Return Value

The style attribute name associated with the HtmlTextWriterStyle enumeration value specified in styleKey.

If styleKey is not a valid HtmlTextWriterStyle object, the GetStyleName method returns an empty string ("").

The following code example shows how to check whether a <label> element is being rendered. If so, it checks whether a Color style attribute has been defined on the element. If the attribute has not been defined, the AddStyleAttribute method is called and the GetStyleName method converts the Color enumeration member into its string representation to pass to the AddStyleAttribute method.

// 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.Equals(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");
    }

Windows 98, Windows Server 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.