aspx中<%:和<%=和<%#之间有什么区别?

时间:2012-02-22 16:20:37

标签: asp.net

  

可能重复:
  What's the difference between <%# %> and <%= %>?
  <%$, <%@, <%=, <%# … what's the deal?

如果这是重复的话,我很抱歉,但谷歌很难让人感到非常困难。

2 个答案:

答案 0 :(得分:11)

<%:是.NET 4.0的新手 - 它相当于HttpUtility.HtmlEncode(Response.Write())

<%=年龄较大,仅代表Response.Write()

<%#binding expression

答案 1 :(得分:6)

Here's一篇关于他们的好文章。总结:

页面指令

<%@ Page Language="C#"  %>

渲染代码

<% Response.Write("Hello World!");  %>

<%= SayHello("Ahmed") %>

<%: DateTime.Now.ToString()  %>

表达式语法

<%$ ConnectionStrings:ConnStrFromWebConfig  %>

<%$ AppSettings:ValueFromWebConfig  %>

<%$ Resources:Resource, Arabic  %>

<%$ RouteValue:year  %>

<%$ YourExpressionPrefix : Any   %>

数据绑定语法

<%# Eval("Name")  %>

<%# Bind("Name")  %>

<%# XPath ("Name")  %>

评论服务器

<%-- <asp:Label runat="server" Text="Label"></asp:Label>-- %>
相关问题