&所述;%:%GT;语法中的中继HTML编码 [英] <%: %> Syntax for HTML Encoding in a repeater

查看:154
本文介绍了&所述;%:%GT;语法中的中继HTML编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

自.NET 4其可能使用的<%:%>语法HTML编码文

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")%>

我所知道的EN code在中继输出的唯一方法是通过使用Server.HtmlDe code。是否有可能使用新的&LT;%:刚刚在结合%>在一个中继器数据绑定,这样我可以去掉难看的HtlmDe code语法。或者是延伸的方法我唯一的选择改善可读性?

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?

推荐答案

没有是不可能的。在&LT;%#是允许绑定数据的计算结果为,但它使用的基本&LT;%

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

你能做的唯一的事情就是重新创建&LT;%:在你的包裹code Html.En code

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

例如:

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

&LT;%:是一条捷径,我想不使用该块的每一个变化已被抓获包括一个shortbut。 MS大概不想创造一吨不同的符号来捕捉各种用途,只支持最常见的用途节外生枝。

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.

这篇关于&所述;%:%GT;语法中的中继HTML编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆