0

In PHP I can use the following to stop HTML from rendering, so it actually displays html as text on the web page:

$html = "<div>Some text</div>";

echo htmlentities($html);

How do I do the same with asp.net pages (vb.net). I am using .NET 3.5.

1
  • Did everyone who ansered this question already know the answer or did they, like me, do one simple google search and get the answer from the first result in the list? Commented Mar 30, 2011 at 11:18

3 Answers 3

3

You could try:

var html = @"<div>Some text</div>";
Response.Write(Server.HtmlEncode(html));

which is the exact translation of your snippet.

BTW, you can find more info on Server.HtmlEncode here.

Sign up to request clarification or add additional context in comments.

Comments

3

You could use HttpServerUtility.HtmlEncode for this:

<%= Server.HtmlEncode("<div>Some text</div>") %>

In .NET 4 you could use a shorthand for this:

<%: "<div>Some text</div>" %>

Comments

2
Server.HtmlEncode("`<div>Some text</div>`");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.