#1 How to display HTML code on an HTML page

Source: Internet
Author: User

Today, the contents of the database inside the output to the interface, encountered a problem. The content of the article does not have all the book out, in a place was staged, tangled for a long time, and then found the problem.

The problem arises in : " <meta charset=" utf-8″> "

In the Database Article table in the article has "<meta charset=" utf-8″> "this thing, and then query out to the server." The result of the query is no problem.

But I use Response.Write (item.   Content); Item. Content is the article's table-of-contents field.

Output to the interface, in the encounter this thing "<meta charset=" utf-8″> "is truncated, the content will not be displayed.

Workaround?

1 (not recommended), is to put this content in <xmp></xmp>,//<pre></pre> and the pre-similar, but it does not parse [email protected]#$%^&* ( ) +=-[]\ ';,./{}| ": <>? These special characters

Want to display a piece of HTML code on a Web page, such as

<div style= "width:300px;height:200px;border:1px dashed Red" ></div>

I'm going to show this code instead of a div.

Several methods:
1) Encode this section of string

2) Call the Httputility.htmlencoder or Server.HTMLEncode method to process the string you want to output and then output it.

Response.Write (Server.HTMLEncode (list. First (). Content));

3) Very simple, directly can be placed in a <TEXTAREA> , the code is as follows:

<title>
Display HTML code
</title>
<body>
<textarea rows=6 cols=60>
<div style= "width:300px;height:200px;border:1px dashed Red" ></div>
</TEXTAREA>
</body>

The easiest way to put it in <textarea> is to use Httputility.htmlencode ().

If you think of the following display will be more time, you can use the third-party control to do.

<div style= "width:300px;height:200px;border:1px dashed Red" ></div>

4) There is also a super simple way to do this:

<xmp>

<div style= "width:300px;height:200px;border:1px dashed Red" ></div>

</xmp>


5) Put <textarea></textrea> suggestion also HTMLEncode () a bit.

or simply HTMLEncode () and put it in the page.

Reference: http://blog.sina.com.cn/s/blog_4ad042e50100dyx2.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.