<%:%> brackets for HTML encoding in ASP.NET 4.0

By chance I found this post about a new feature in ASP.NET 4.0: expressions enclosed in these new brackets <%: Content %>should be displayed as HTML encoded.

I tried this inside a data label in a FormView, for example:

<asp:Label ID="MyLabel" runat="server" Text='<%: Eval("MyTextProperty") %>' />

But this does not work: the text property contains script tags (for testing), but the output is empty. Using the traditional way of working:

<asp:Label ID="MyLabel" runat="server"
    Text='<%# HttpUtility.HtmlEncode(Eval("MyTextProperty")) %>' />

What am I doing wrong?

(On the side: I'm too stupid to find any information: Google refuses to search for this thing. VS2010 MSDN online help offers a lot of hits, but nothing related to my search. Search in Stackoverflow too. I donโ€™t know how these โ€œthingsโ€ (brackets I mean) are officially called to have a better search query.)

!

!

+5
2

, <%#%> Eval ( Bind) (<%=%> <%:%>), Eval.

+8

<%#: %> HTML-. ( ":" "#" ). :

Text='<%#: Eval("PropertyToEval") %>'
+3

All Articles