Name
HTMLEncode —
Server.HTMLEncode
(strHTMLString
)
Synopsis
If you ever need to display the actual HTML code involved in an HTML page or ASP script, you must use the HTMLEncode method of the Server object. The HTMLEncode method of the Server object allows you to encode the HTML string so that, when it is displayed in the browser, the browser does not simply interpret the HTML as instructions for text layout.
Parameters
-
strHTMLString The string whose HTML code you wish to encode for display on the client machine.
Example
<% ' The following code encodes these HTML tags so that they can ' be displayed without interpretation on the client browser: ' <TABLE><TR><TD></TD></TR></TABLE> Dim strOldHTML Dim strNeutralCode strOldHTML = "<TABLE><TR><TD>" strNeutralCode = Server.HTMLEncode(strOldHTML) ' The variable strNeutralCode now holds the following code: ' <TABLE><TR><TD> ' but will be displayed on the client's machine as ' <TABLE><TR><TD> ' and the <TABLE><TR><TD> will be ' seen only if you view the source code on the client. Response.Write strNeutralCode %>
Notes
The HTMLEncode method is a straightforward method that is simple to use. It makes it possible to display the source code of your HTML page or to demonstrate the use of various HTML tags in a web page. It is also invaluable for displaying the output of database queries.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access