HtmlTextWriter.WriteAttribute Method (String, String)
Writes the specified markup attribute and value to the output stream.
Assembly: System.Web (in System.Web.dll)
Use themethod to write markup attributes and their values with no encoding. The method writes the attribute value enclosed in double quotation marks ("). If value is null, the method writes only the attribute name.
Notes to Inheritors:
In derived classes, you can override themethod to define custom rules for writing attributes and their values. For example, you could write code that allowed the method to write an attribute with an empty value.
The following code example demonstrates rendering an <img> element in which both overloads of the WriteAttribute method are called. The code example uses the following process:
Calls the WriteBeginTag method, which renders the opening characters of the element.
Calls theoverload, which writes an alt attribute and its value to the <img> element.
Calls the WriteAttribute(String, String, Boolean) overload to render a custom myattribute attribute, with a value of No "encoding" required, and then sets fEncode to false.
Closes the opening tag of the element, and then calls the WriteEndTag method to close the <img> element.
This code example generates the following markup:
<img alt="AtlValue" myattribute="No "encoding" required">
Available since 1.1