Writes the specified markup attribute and value to the output stream.
Assembly: System.Web (in System.Web.dll)
Public Overridable Sub WriteAttribute ( _ name As String, _ value As String _ )
public virtual void WriteAttribute( string name, string value )
public: virtual void WriteAttribute( String^ name, String^ value )
abstract WriteAttribute : name:string * value:string -> unit override WriteAttribute : name:string * value:string -> unit
Parameters
- name
- Type: System.String
The attribute to write to the output stream.
- value
- Type: System.String
The value assigned to the attribute.
Use the WriteAttribute method to write markup attributes and their values with no encoding. The WriteAttribute method writes the attribute value enclosed in double quotation marks ("). If value is null, the WriteAttribute method writes only the attribute name.
Notes to Inheritors
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 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">
</img>
' Create a manually rendered tag. writer.WriteBeginTag("img") writer.WriteAttribute("alt", "AtlValue") writer.WriteAttribute("myattribute", "No "encoding " required", False) writer.Write(HtmlTextWriter.TagRightChar)
// Create a manually rendered tag. writer.WriteBeginTag("img"); writer.WriteAttribute("alt", "AtlValue"); writer.WriteAttribute("myattribute", "No "encoding " required", false); writer.Write(HtmlTextWriter.TagRightChar); writer.WriteEndTag("img");
// Create a manually rendered tag. writer->WriteBeginTag( "img" ); writer->WriteAttribute( "alt", "AtlValue" ); writer->WriteAttribute( "myattribute", "No "encoding " required", false ); writer->Write( HtmlTextWriter::TagRightChar ); writer->WriteEndTag( "img" );
.NET Framework
Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.