System.Web.UI.HtmlTextWriter.AddAttribute Method

Adds the markup attribute and the attribute value to the opening tag of the element that the System.Web.UI.HtmlTextWriter object creates with a subsequent call to the erload:System.Web.UI.HtmlTextWriter.RenderBeginTag method, with optional encoding.

Syntax

public virtual void AddAttribute (HtmlTextWriterAttribute key, string value, bool fEncode)

Parameters

key
An System.Web.UI.HtmlTextWriterAttribute that represents the markup attribute to add to the output stream.
value
A string containing the value to assign to the attribute.
fEncode
true to encode the attribute and its value; otherwise, false.

Remarks

Use the HtmlTextWriter.AddAttribute(HtmlTextWriterAttribute, string, bool) overload of the HtmlTextWriter.AddAttribute(HtmlTextWriterAttribute, string, bool) method to render a standard markup attribute, with optional encoding.

For an instance of any given markup element, the System.Web.UI.HtmlTextWriter class maintains a list of attributes for that element. When the erload:System.Web.UI.HtmlTextWriter.RenderBeginTag method is called, any attributes added by the erload:System.Web.UI.HtmlTextWriter.AddAttribute are rendered to the opening tag of the element. The list of attributes is then cleared from the System.Web.UI.HtmlTextWriter object.

Use the HtmlTextWriter.AddAttribute(HtmlTextWriterAttribute, string, bool) method with fEncode set to true, if the attribute can possibly contain a quotation mark ("), a less than sign (<), or an ampersand (&). The method call will encode the attribute to meet the requirements of the requesting device. You can set fEncode to false, if you know that none of these characters will be generated, or if you know that the attribute is already encoded.

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