HtmlTextWriter.WriteEncodedText(String) Method

Definition

Encodes the specified text for the requesting device, and then writes it to the output stream.

C#
public virtual void WriteEncodedText(string text);

Parameters

text
String

The text string to encode and write to the output stream.

Exceptions

text is null.

Examples

The following code example shows how to use the WriteEncodedText method to write the encoded markup &lt;custID&gt; &amp; &lt;invoice#&gt; to the output stream. The WriteBreak method writes <br />.

C#
// Assign a value to a string variable,
// encode it, and write it to a page.
colHeads = "<custID> & <invoice#>"; 
writer.WriteEncodedText(colHeads);
writer.WriteBreak();

Remarks

Use the WriteEncodedText method when a string contains angle brackets (< or >) or an ampersand (&).

The WriteEncodedText method uses the HtmlEncode method to perform the encoding and also converts Unicode character 00A0 to &nbsp;.

Applies to

Product Versions
.NET Framework 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

See also