Skip to content Skip to sidebar Skip to footer

<%: %> Syntax For Html Encoding In A Repeater

Since .NET 4 its possible to use the <%: %> syntax for HTML Encoding of text. In a repeater I use the following syntax to display data <%# DataBinder.Eval(Container.DataI

Solution 1:

As of ASP.NET 4.5 this is possible using the new <%#: %> notation

Solution 2:

No it is not possible. The <%# is allowing the evaulation of binding data but it use the basic <% block.

The only thing you can do is recreate the <%: by wrapping your code in Html.Encode.

Eg:

<%# Html.Encode(DataBinder.Eval(Container.DataItem, "fieldlabel")) %> 

The <%: is a shortcut and I guess not every variation of the use of the blocks has been captured to include a shortbut. MS probably didn't want to complicate the issue by creating a ton of different symbols to capture the various uses and only support the most common use.

Solution 3:

I think the answer is no, based on this question.

Meaning of the various symbols in .aspx page of asp.net

Solution 4:

It is possible but need to work more:

Please use below syntax

<asp:Literal ID="fieldlabel" runat="server" Mode="Encode"Text='<%#Eval("fieldlabel")%>"></asp:Literal>

Post a Comment for "<%: %> Syntax For Html Encoding In A Repeater"