Ask Learn
Preview
Please sign in to use this experience.
Sign inThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Writes a markup attribute and its value to the output stream.
WriteAttribute(String, String, Boolean) |
Writes the specified markup attribute and value to the output stream, and, if specified, writes the value encoded. |
WriteAttribute(String, String) |
Writes the specified markup attribute and value to the output stream. |
Writes the specified markup attribute and value to the output stream, and, if specified, writes the value encoded.
public:
virtual void WriteAttribute(System::String ^ name, System::String ^ value, bool fEncode);
public virtual void WriteAttribute(string name, string value, bool fEncode);
abstract member WriteAttribute : string * string * bool -> unit
override this.WriteAttribute : string * string * bool -> unit
Public Overridable Sub WriteAttribute (name As String, value As String, fEncode As Boolean)
The markup attribute to write to the output stream.
The value assigned to the attribute.
true
to encode the attribute and its assigned value; otherwise, false
.
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 );
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");
' Create a manually rendered tag.
writer.WriteBeginTag("img")
writer.WriteAttribute("alt", "AtlValue")
writer.WriteAttribute("myattribute", "No "encoding " required", False)
writer.Write(HtmlTextWriter.TagRightChar)
Use the WriteAttribute method to write markup attributes and their values with or without encoding. The WriteAttribute method uses the HtmlAttributeEncode method to do the 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.
In derived classes, you can override the WriteAttribute(String, String, Boolean) method to define custom rules for writing attributes and their values. For example, you could write code that allowed the WriteAttribute(String, String, Boolean) method to write an attribute with an empty value.
Product | Versions |
---|---|
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
Writes the specified markup attribute and value to the output stream.
public:
virtual void WriteAttribute(System::String ^ name, System::String ^ value);
public virtual void WriteAttribute(string name, string value);
abstract member WriteAttribute : string * string -> unit
override this.WriteAttribute : string * string -> unit
Public Overridable Sub WriteAttribute (name As String, value As String)
The attribute to write to the output stream.
The value assigned to the attribute.
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 );
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");
' Create a manually rendered tag.
writer.WriteBeginTag("img")
writer.WriteAttribute("alt", "AtlValue")
writer.WriteAttribute("myattribute", "No "encoding " required", False)
writer.Write(HtmlTextWriter.TagRightChar)
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.
In derived classes, you can override the WriteAttribute(String, String) method to define custom rules for writing attributes and their values. For example, you could write code that allowed the WriteAttribute(String, String) method to write an attribute with an empty value.
Product | Versions |
---|---|
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET feedback
.NET is an open source project. Select a link to provide feedback:
Please sign in to use this experience.
Sign in