Server. HTMLEncode makes the code appear as source code on the page

  • 2020-12-05 17:07:53
  • OfStack

Today, because the program will write to the database html source code in the form of html source code displayed in the page, not interpreted by the browser. I found N for a long time do not know how to do then look at the next 1 program which has the function of modifying the template. I found 1 asp method and I wrote it down

Server.HTMLEncode

HTMLEncode

1. The HTMLEncode method applies HTML encoding to the specified string.

grammar
Server.HTMLEncode( string )

parameter

string

Specifies the string to encode.
The sample

The script


<%= Server.HTMLEncode("The paragraph tag: <P>") %>

The output

The paragraph tag: & lt;P & gt;

Note that the above output will be displayed by the Web browser

The paragraph tag: < P >
If you look at the source file under 1 or open an Web page textually, you can see HTML encoded

2. Relevant examples:

rs("content")=Server.Htmlencode(Request("content")) :

rs("content") means that rs is an recordset object and content is a field in a database table; The recordset object can manipulate every record in a database table, as well as every field in it.

Server.Htmlencode is used to convert some code to html format.

Request("content") is the value of the last page returned with an element named content; It could be a text box in a form, or it could be an querystring type thing
But judging by name and custom, it is a multi-line text box for a form, because it is used to place content.
The whole idea is that it puts the value in the text box from the last submission page into the content field in the record that is now open in the database.


Related articles: