HtmlTextWriter.WriteEncodedText(String) Method

Definition

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

public:
 virtual void WriteEncodedText(System::String ^ text);
public virtual void WriteEncodedText (string text);
abstract member WriteEncodedText : string -> unit
override this.WriteEncodedText : string -> unit
Public Overridable Sub WriteEncodedText (text As String)

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 />.

// Assign a value to a string variable,
// encode it, and write it to a page.
colHeads = "<custID> & <invoice#>"; 
writer.WriteEncodedText(colHeads);
writer.WriteBreak();
' 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

See also