HtmlTextWriter.WriteAttribute Method (String, String, Boolean)
Writes the specified markup attribute and value to the output stream, and, if specified, writes the value encoded.
Assembly: System.Web (in System.Web.dll)
In derived classes, you can override the WriteAttribute method to define custom rules for writing attributes and their values. For example, you could write code that allowed the WriteAttribute 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 the WriteAttribute(String, String) overload, which writes an alt attribute and its value to the <img> element.
Calls the 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">
Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.