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.
This example demonstrates how to use the HtmlEncode method to ensure that a browser correctly displays text. Characters in a string such as <, >, and & are rendered incorrectly unless they are escaped as <, >, and &.
Example
The following code example encodes a string to be displayed in a browser. It encodes the string named TestString, which contains the text This is a <Test String>, and copies it into the string named EncodedString as This is a <Test String>.
Dim TestString As String = "This is a <Test String>"
Dim EncodedString As String = Server.HtmlEncode(TestString)
This example requires a reference to System.Web.dll.