HTML Encodes a stringSyntax:
x = Server.HTMLEncode( string )
Parameters:
string - string to be encoded
The method returns new string containing HTML encoded version of the passed
parameter.
Examples:
JScript/VBScript:
<%= Server.HTMLEncode("Bolding in HTML can be made using the <B> or
<STRONG> tags") %>
It is important to use that function if you are expecting the output to contain parts
that can be treated as a HTML tags. Failing to do so may corrupt your page visual
representation.
For example if your application has pages saving something to a data base and pages
showing it - you may want to allow writing some HTML content in the DB. In this case you
will save the content "as is" without encoding to the DB but when you display it
in the TEXTAREA for editing (in another page) you must HTMLEncode it. If not tags in the
content placed between <TEXTAREA ..> </TEXTAREA> tags can contain everything
including </TEXTAREA> and this will tell the browser that the TEXTAREA ends in the
incorrect place.
Remarks:
In any case when you are expecting the content you are writing to the response (of
text/html content type) to contain some HTML tags or characters sequences that can be
mistaken for HTML tags you must use this method to encode the output.
Applies to: Server object
See also: Server.URLEncode, Response.Write |