how to encode HTML in ASP.NET

RegisterLogin
how to encode HTML in ASP.NET
Post Description: Encoding Html In Asp.net Is Easy If You Know How To, We Will Show You How You Can Make Html Characters View In Your Html Code
Tags: How, To, Encode, Html, In, Asp.net
This Post Was Posted On Dec 10, 2009 By Webune Tutorials #2880
if you are familiar with PHP, there is a function called htmlentities and htmlspecialchars()

well, in ASP.NET there is a similar object you can use to change HTML code into text instead of the actual code, its called Sever.HTMLEncode()

for example, let say i want to show this on my HTML:

ASP CODE:
<%
Dim HTMLString
Dim CleanedHTML

HTMLString = "These are bold letters using the <strong> tag"
CleanedHTML = Server.HTMLEncode(HTMLString)

Response.Write CleanedHTML
%>


the output will look like this:

These are bold letters using the <strong> tag

if you ever do need to show the actual HTML code into your HTML pages or ASP scripts, you must use the HTMLEncode method fo 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 interpret the HTML code as instructions for text layout instead as actual text on the web page.. hope that helps

Sever.HTMLEncode()



&&&&&&&&
Leave Your Comments
Related Pages: [Add Your Website]
Post New Topic
raul
#3500 1
tell me how to show encoded html response.write
Feb 21, 2010 Reply Report abuse
©2012 Webune Forums - Thu Dec 13, 2012 2:16 am
Powered by: Webune Forums V3