你能告诉之间与其中的差别;%=%&gt;中&LT;%#%&GT;和&lt;%$%&GT; ASP.NET EX pressions? [英] Can you tell the differences between <%= %>, <%# %> and <%$ %> ASP.NET expressions?
问题描述
您可以简单地列出之间的&LT的差异;%=%&GT;
,&LT;%#%&GT;
和&LT;%$%&GT;
通过给一个简单的例子
也许有,只需要那些EX pressions之一使用?
&LT; %%&GT;
&LT;%this.CallMethod()%&GT;
- 的基本code座。
&其中;%=%GT;
&LT;%=文本%&GT;
- 的嵌入式code语法。同写&LT;%的Response.Write(文本)%&GT;
&LT;%:%&GT;
&LT;%:文字%&GT;
- 同上,除了它是一个速记&LT;%= Server.HtmlEn code(文本)%&GT;
。这是<一个href="http://weblogs.asp.net/scottgu/archive/2010/04/06/new-lt-gt-syntax-for-html-encoding-output-in-asp-net-4-and-asp-net-mvc-2.aspx"相对=nofollow>在ASP.NET 4 引入,是默认使用的语法。
&LT;%#%&GT;
&LT;%#的eval(的ColumnName)%&GT;
- 用于的绑定。
&LT;%$%&GT;
&LT;%$的AppSettings:settingName%&GT;
- 的的 有preFIX如的AppSettings
,的ConnectionStrings EX pression语法
或资源
然后:
后跟实际EX pression。它可以作为一个速记访问资源内联。你甚至可以创建你自己的语法这里使用(感谢@Thomas Levesque的)。此外查看MSDN 了解更多信息。
&LT;%@%&GT;
&LT;%@页面语言=C#%&GT;
- 的的指令语法的页/控制设置非常有用。
&LT;% - - %&GT;
&LT;% - 这是一个注释 - %&GT;
- <一个href="http://weblogs.asp.net/scottgu/archive/2006/07/09/Tip_2F00_Trick_3A00_-Using-Server-Side-Comments-with-ASP.NET-2.0-.aspx"相对=nofollow>服务器端注释语法。这不同于HTML &LT;! - 评论 - &GT;
语法,它的不会的在输出渲染<。 / P>
Can you briefly list the differences between <%= %>
, <%# %>
and <%$ %>
by giving a simple example?
Maybe one that requires only one of those expressions to be used?
<% %>
<% this.CallMethod() %>
- Basic code block that executes the statements inside.
<%= %>
<%= "text" %>
- Embedded code syntax. Same as writing <% Response.Write("text") %>
.
<%: %>
<%: "text" %>
- Same as above except it's a shorthand for <%= Server.HtmlEncode("text") %>
. This was introduced in ASP.NET 4 and is the default syntax used.
<%# %>
<%# Eval("ColumnName") %>
- Used for databinding.
<%$ %>
<%$ AppSettings: settingName %>
- The expression syntax has a prefix such as AppSettings
, ConnectionStrings
, or Resources
and then a :
followed by the actual expression. It can be used as a shorthand to access resources inline. You can even create your own syntax used here (Thanks @Thomas Levesque). Also see MSDN for more info.
<%@ %>
<%@ Page language="C#" %>
- The directive syntax useful for page/control settings.
<%-- --%>
<%-- This is a comment --%>
- Server-side comment syntax. This differs from the HTML <!-- a comment -->
syntax in that it won't be rendered in the output.
这篇关于你能告诉之间与其中的差别;%=%&gt;中&LT;%#%&GT;和&lt;%$%&GT; ASP.NET EX pressions?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!