<%:%> Syntax for HTML encoding in the repeater

Since .NET 4, you can use the syntax <%:%> to encode HTML text.

In the repeater, I use the following syntax to display data

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

The only way I can code the output in the repeater is with "Server.HtmlDecode". Is it possible to use the new <%:%> in the repeater only in conjunction with data binding so that I can remove the ugly HtlmDecode syntax. Or is the extension method my only way to improve readability?

+3
source share
4 answers

, . <%# , <%.

, , <%:, Html.Encode.

:

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

<%: - , , , shortbut. MS, , , .

+2

ASP.NET 4.5 <%#: %>

+4

, :

,

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

All Articles