HtmlTextWriter.WriteEncodedText Method

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

Namespace: System.Web.UI
Assembly: System.Web (in system.web.dll)

public virtual void WriteEncodedText (
	string text
)
public void WriteEncodedText (
	String text
)
public function WriteEncodedText (
	text : String
)
Not applicable.

Parameters

text

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

Exception typeCondition

ArgumentNullException

text is a null reference (Nothing in Visual Basic).

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

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();

Windows 98, Windows Server 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0

Community Additions

ADD
Show: