Op Englesch liesen Editéieren

Deelen iwwer


HtmlTextWriter.GetStyleName(HtmlTextWriterStyle) Method

Definition

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

C#
protected string GetStyleName(System.Web.UI.HtmlTextWriterStyle styleKey);

Parameters

styleKey
HtmlTextWriterStyle

The HtmlTextWriterStyle to obtain the style attribute name for.

Returns

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

Examples

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.

C#
// 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");
    }

Remarks

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

Applies to

Produkt Versiounen
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

See also