HtmlTextWriter.AddStyleAttribute Method (HtmlTextWriterStyle, String)
Assembly: System.Web (in System.Web.dll)
abstract AddStyleAttribute : key:HtmlTextWriterStyle * value:string -> unit override AddStyleAttribute : key:HtmlTextWriterStyle * value:string -> unit
The HtmlTextWriter class maintains a list of styles for the markup elements it renders. When the RenderBeginTag method is called, any styles added by the AddStyleAttribute method are rendered to the opening tag of the element. The list of styles is then cleared.
The coding pattern for rendering markup elements is as follows:
The following code example demonstrates how to use part of an override of the RenderBeginTag method in a class derived from the HtmlTextWriter class. The code checks whether a <Label> element is being rendered. If so, the IsStyleAttributeDefined method is called to check whether a Color style attribute has been defined for the <Label> element. If a Color attribute has not been defined, the code calls this overload of the AddStyleAttribute method to add the Color attribute to the style attribute, and then set its value to red.