HtmlTextWriter.IsStyleAttributeDefined Method

Definition

Determines whether a markup style attribute is rendered during the next call to the RenderBeginTag method.

Overloads

IsStyleAttributeDefined(HtmlTextWriterStyle)

Determines whether the specified markup style attribute is rendered during the next call to the RenderBeginTag method.

IsStyleAttributeDefined(HtmlTextWriterStyle, String)

Determines whether the specified markup style attribute and its value are rendered during the next call to the RenderBeginTag method.

IsStyleAttributeDefined(HtmlTextWriterStyle)

Determines whether the specified markup style attribute is rendered during the next call to the RenderBeginTag method.

protected:
 bool IsStyleAttributeDefined(System::Web::UI::HtmlTextWriterStyle key);
protected bool IsStyleAttributeDefined (System.Web.UI.HtmlTextWriterStyle key);
member this.IsStyleAttributeDefined : System.Web.UI.HtmlTextWriterStyle -> bool
Protected Function IsStyleAttributeDefined (key As HtmlTextWriterStyle) As Boolean

Parameters

key
HtmlTextWriterStyle

The HtmlTextWriterStyle associated with the attribute.

Returns

true if the attribute will be rendered during the next call to the RenderBeginTag method; otherwise, false.

Examples

The following code example shows how to check whether a <label> element is being rendered. If so, the IsStyleAttributeDefined method checks whether a Color style attribute has been defined on the element. If the Color attribute has not been defined, the AddStyleAttribute method defines the Color attribute and sets its value to 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)
{
    // 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

Remarks

To get the value that will be rendered with the specified style attribute, use the IsStyleAttributeDefined(HtmlTextWriterStyle, String) overload of the IsStyleAttributeDefined method.

See also

Applies to

IsStyleAttributeDefined(HtmlTextWriterStyle, String)

Determines whether the specified markup style attribute and its value are rendered during the next call to the RenderBeginTag method.

protected:
 bool IsStyleAttributeDefined(System::Web::UI::HtmlTextWriterStyle key, [Runtime::InteropServices::Out] System::String ^ % value);
protected bool IsStyleAttributeDefined (System.Web.UI.HtmlTextWriterStyle key, out string value);
member this.IsStyleAttributeDefined : System.Web.UI.HtmlTextWriterStyle * string -> bool
Protected Function IsStyleAttributeDefined (key As HtmlTextWriterStyle, ByRef value As String) As Boolean

Parameters

key
HtmlTextWriterStyle

The HtmlTextWriterStyle associated with the attribute.

value
String

The value assigned to the style attribute.

Returns

true if the attribute and its value will be rendered during the next call to the RenderBeginTag method; otherwise, false.

Remarks

If the IsStyleAttributeDefined method returns true, the value to be assigned to the HtmlTextWriterStyle attribute is returned in the value parameter.

See also

Applies to