asp.net 输出编码?
我什至不确定我是否称此为正确的事情。我刚刚开始接触 ASP.Net,当然我开始看到像 <% "Code here" %> 这样的语法。到目前为止我已经看到了<%: %>、<%= %>、<%# %>。当然,谷歌不喜欢这些符号进行搜索,因此搜索帮助是徒劳的:)。也许这种类型的语法来自经典 ASP(我从未使用过)?除了我列出的之外,我不知道是否还有其他的。有谁有一个好的链接或者可以写一个好的解释。我还认为它用于 vb.net 的 XML 文字中。我还认为它与某些函数相关,例如“Eval”函数。
I'm not even sure i'm calling this the right thing. I'm just starting to get into ASP.Net and of course i'm starting to see syntax like <% "Code here" %>. So far i've seen <%: %>, <%= %>, <%# %>. Of course google doesn't like these symbols for searching so searching for help is futile :). Maybe this type of syntax is back from classic ASP (which i never used)? I don't know if there are any others than what i listed. Does anyone have a good link or can write up a good explanation. I also think it used in XML literals for vb.net. I also think its associated with certain functions like the "Eval" function.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
简而言之,
<%# %>
用于数据绑定(例如在ListView
中,您要指定元素必须如何显示在一页)。如果未调用this.Page.DataBind()
(或控件级绑定),则不会显示任何内容。<%= %>
用于显示任意字符串。另一方面,<% %>
可以让您做任何您想做的事情,但您必须使用Response.Write()
来输出某些内容。<%: %>
是 .NET Framework 4.0 中的一项新功能,其功能与<%= %>
相同,但对输出进行编码显示为 HTML。这称为内联标记,因此搜索“asp.net 内联标记”可能会为您提供更多信息。
To be short,
<%# %>
is used for data binding (for example in aListView
where you want to specify how elements must be displayed on a page). Ifthis.Page.DataBind()
(or control-level binding) is not called, nothing will be displayed.<%= %>
is used to display any string.<% %>
on the other hand would let you to do any stuff you want, but you must useResponse.Write()
to output something.<%: %>
is a new feature in .NET Framework 4.0 which does the same thing as<%= %>
, but encodes output to be displayed as HTML.This is called inline tags, so searching for "asp.net inline tag" may give you additional info.