HtmlTextWriter.IsStyleAttributeDefined Method (HtmlTextWriterStyle)
.NET Framework 2.0
Determines whether the specified markup style attribute is rendered during the next call to the RenderBeginTag method.
Namespace: System.Web.UI
Assembly: System.Web (in system.web.dll)
Assembly: System.Web (in system.web.dll)
protected boolean IsStyleAttributeDefined ( HtmlTextWriterStyle key )
protected function IsStyleAttributeDefined ( key : HtmlTextWriterStyle ) : boolean
Not applicable.
Parameters
- key
The HtmlTextWriterStyle associated with the attribute.
Return Value
true if the attribute will be rendered during the next call to the RenderBeginTag method; otherwise, false.To get the value that will be rendered with the specified style attribute, use the IsStyleAttributeDefined(HtmlTextWriterStyle,String) overload of the IsStyleAttributeDefined method.
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.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");
}
Community Additions
ADD
Show: