|Important||This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer|
How to: Validate Text for Display in a Web Browser in Visual Basic
This example demonstrates how to use themethod to ensure that a browser correctly displays text. Characters in a string such as <, >, and & are rendered incorrectly unless they are escaped as <, >, and &.
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.