17

It seems I am missing something. But ever since .Net 4.0 came out I have been seeing reference to <%: %> syntax for ASP.NET. It seems like it is similar to <%= %> but clearly there is a reason for the new syntax. I tried google but searching <%: %> doesn't seem to return anything. What does the <%: %> syntax do? Was it introduced in .Net 4.0 or 3.5? Can someone enlighten me?

Edited: Please provide reference or examples

John Hartsock
  • 85,422
  • 23
  • 131
  • 146
  • 1
    It automatically Html encodes the output. It's new in 4. I'm sure you will get more information from someone in an answer though. – jjnguy Oct 20 '10 at 15:02

2 Answers2

22

i believe the <%: %> is auto HtmlEncoding

this post from Scott Gu will help to explain - it was introduced in .net 4 and MVC2

http://weblogs.asp.net/scottgu/archive/2010/04/06/new-lt-gt-syntax-for-html-encoding-output-in-asp-net-4-and-asp-net-mvc-2.aspx

stack72
  • 8,198
  • 1
  • 31
  • 35
4

: does html encoding.

Scott Guthrie has a nice post describing it in detail.

Don't use this where it is already encoded otherwise it will double encoded it. This is useful if you want to output things like HTML, though.

hunter
  • 62,308
  • 19
  • 113
  • 113