System.Web.UI.HtmlTextWriter.AddStyleAttribute Method

Adds the markup style attribute associated with the specified System.Web.UI.HtmlTextWriterStyle value and the attribute value to the opening markup tag created by a subsequent call to the erload:System.Web.UI.HtmlTextWriter.RenderBeginTag method.

Syntax

public virtual void AddStyleAttribute (HtmlTextWriterStyle key, string value)

Parameters

key
An System.Web.UI.HtmlTextWriterStyle that represents the style attribute to add to the output stream.
value
A string that contains the value to assign to the attribute.

Remarks

Use the HtmlTextWriter.AddStyleAttribute(HtmlTextWriterStyle, string) overload of the HtmlTextWriter.AddStyleAttribute(HtmlTextWriterStyle, string) method when the style is a member of the System.Web.UI.HtmlTextWriterStyle enumeration and is known before run time.

The System.Web.UI.HtmlTextWriter class maintains a list of styles for the markup elements it renders. When the erload:System.Web.UI.HtmlTextWriter.RenderBeginTag method is called, any styles added by the erload:System.Web.UI.HtmlTextWriter.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:

Requirements

Namespace: System.Web.UI
Assembly: System.Web (in System.Web.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0