In ASP.Net, what is the difference between <%= x %>
and <%# x %>
?
在ASP.Net中,<%= x%>和<%#x%>之间有什么区别?
4 个解决方案
#1
56
See this question:
When should I use # and = in ASP.NET controls?
看到这个问题:我什么时候应该在ASP.NET控件中使用#和=?
Summary from those answers:
这些答案摘要:
There are a several different 'bee-stings':
有几种不同的'蜜蜂蜇':
-
<%@
- Page/Control/Import/Register directive - <%@ - 页面/控制/导入/注册指令
-
<%$
- Resource access and Expression building - <%$ - 资源访问和表达式构建
-
<%=
- Explicit output to page, equivalent to<% Response.Write( ) %>
- <%= - 显式输出到页面,相当于<%Response.Write()%>
-
<%#
- Data Binding. It can only used where databinding is supported, or at the page level if you callPage.DataBind()
in your code-behind. - <%# - 数据绑定。它只能在支持数据绑定的地方使用,或者在代码隐藏中调用Page.DataBind()时在页面级别使用。
-
<%--
- Server-side comment block - <% - - 服务器端注释块
-
<%:
- Equivalent to<%=
, but it also html-encodes the output. - <%: - 相当于<%=,但它也对输出进行了html编码。
#2
4
<%#
is data binding expression syntax.
<%#是数据绑定表达式语法。
<%=
resolves the expression returns its value to the block (Embedded code block reference) - effectively shorthand for <% Response.Write(...); %>
<%=解析表达式将其值返回到块(嵌入式代码块引用) - 有效地缩写为<%Response.Write(...); %>
#3
3
<%# is the databinding directive, <%= is a shortcut for "Response.Write"
<%#是数据绑定指令,<%=是“Response.Write”的快捷方式
#4
3
<%= x %> is shorthand for Response.Write()
<%= x%>是Response.Write()的简写
<%# x %> indicates a databind.
<%#x%>表示数据绑定。
<% %> indicates server-executable code.
<%%>表示服务器可执行代码。
#1
56
See this question:
When should I use # and = in ASP.NET controls?
看到这个问题:我什么时候应该在ASP.NET控件中使用#和=?
Summary from those answers:
这些答案摘要:
There are a several different 'bee-stings':
有几种不同的'蜜蜂蜇':
-
<%@
- Page/Control/Import/Register directive - <%@ - 页面/控制/导入/注册指令
-
<%$
- Resource access and Expression building - <%$ - 资源访问和表达式构建
-
<%=
- Explicit output to page, equivalent to<% Response.Write( ) %>
- <%= - 显式输出到页面,相当于<%Response.Write()%>
-
<%#
- Data Binding. It can only used where databinding is supported, or at the page level if you callPage.DataBind()
in your code-behind. - <%# - 数据绑定。它只能在支持数据绑定的地方使用,或者在代码隐藏中调用Page.DataBind()时在页面级别使用。
-
<%--
- Server-side comment block - <% - - 服务器端注释块
-
<%:
- Equivalent to<%=
, but it also html-encodes the output. - <%: - 相当于<%=,但它也对输出进行了html编码。
#2
4
<%#
is data binding expression syntax.
<%#是数据绑定表达式语法。
<%=
resolves the expression returns its value to the block (Embedded code block reference) - effectively shorthand for <% Response.Write(...); %>
<%=解析表达式将其值返回到块(嵌入式代码块引用) - 有效地缩写为<%Response.Write(...); %>
#3
3
<%# is the databinding directive, <%= is a shortcut for "Response.Write"
<%#是数据绑定指令,<%=是“Response.Write”的快捷方式
#4
3
<%= x %> is shorthand for Response.Write()
<%= x%>是Response.Write()的简写
<%# x %> indicates a databind.
<%#x%>表示数据绑定。
<% %> indicates server-executable code.
<%%>表示服务器可执行代码。