views:

126

answers:

3

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

+2  A: 

: 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
+10  A: 

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

PaulStack
This is correct, <%: %> is pretty much equivalent to doing <%= Html.Encode(...) %>
ridecar2
its also equivalent to doing <%= Server.HtmlEncode() %>
PaulStack
A: 

see the following link

Are <%: and <%= the same thing as embbed code (expression) blocks

Gnought