4

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.DataItem, "fieldlabel")%>

The only way I know of to encode the output in the repeater is by using "Server.HtmlDecode". Is it possible to use the new <%: %> in a repeater just in combination with databinding so that I can remove the ugly HtlmDecode syntax. Or is an extention method my only option to improved the readability?

Ivo
  • 3,406
  • 4
  • 33
  • 56

4 Answers4

7

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

freefaller
  • 19,368
  • 7
  • 57
  • 87
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.

Kelsey
  • 47,246
  • 16
  • 124
  • 162
  • 3
    Please note, as of [.NET 4.5 this is possible](http://www.asp.net/aspnet/overview/aspnet-and-visual-studio-2012/whats-new#_Toc318097391) using the new `<%#: %>` notation – freefaller Jan 15 '16 at 11:43
  • @freefaller thanks for the update, after almost 5 years I guess they finally addressed the issue :) – Kelsey Jan 15 '16 at 14:46
1

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

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

Community
  • 1
  • 1
Doug Chamberlain
  • 11,192
  • 9
  • 51
  • 91
0

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>
Racks
  • 11
  • 1