Pardon my ASP ignorance, but what's the difference?
请原谅我对ASP的无知,但是有什么区别呢?
5 个解决方案
#1
18
These are somewhat informally referred to as "bee stings". There are 4 types:
这些被非正式地称为“蜜蜂螫刺”。有四类:
<%# %>
is invoked during the DataBinding phase.
<%# %>在数据库阶段被调用。
<%= %>
is used to get values from code to the UI layer. Meant for backward compatibility with ASP applications. Shouldn't use in .NET.
<%= %>用于从代码获取值到UI层。用于与ASP应用程序向后兼容。不应该在。net中使用。
<%@ %>
represents directives and allow behaviors to be set without resorting to code.
<%@ %>表示指令,允许不通过代码设置行为。
<%: %>
(introduced in ASP.NET 4) is the same as %=
, but with the added functionality of HtmlEncoding the output. The intention is for this to be the default usage (over %=
) to help shield against script injection attacks.
<%: %>(在ASP中引入)。NET 4)与%=相同,但是使用HtmlEncoding的附加功能输出。这样做的目的是作为默认用法(超过%=)来帮助屏蔽脚本注入攻击。
Directives specify settings that are used by the page and user-control compilers when the compilers process ASP.NET Web Forms pages (.aspx files) and user control (.ascx) files.
当编译器处理ASP时,指令指定页面和用户控制编译器使用的设置。NET Web Forms页面(。aspx文件)和用户控制(.ascx)文件。
ASP.NET treats any directive block (<%@ %>) that does not contain an explicit directive name as an @ Page directive (for a page) or as an @ Control directive (for a user control).
ASP。NET将不包含显式指令名的任何指令块(<%@ %>)视为@ Page指令(用于页面)或@ Control指令(用于用户控件)。
@Esteban - Added a msdn link to directives. If you need...more explanation, please let me know.
@Esteban -添加msdn链接到指令。如果你需要…更多的解释,请告诉我。
#2
3
参见http://weblogs.asp.net/leftslipper/archive/2007/06/29/how-asp-net-databinding-deals-with-eval-and-bind-statements.aspx
As Albert says, it's all to do with parsing databinding statements.
正如Albert所说,这一切都与解析数据库语句有关。
#3
2
The # version is used while data binding. <%= is just a simple Response.Write
在数据绑定时使用#版本。<%=只是一个简单的Response.Write
#4
2
Not entirely related to the question, there's another related notation in asp.net called Expression Builder:
与这个问题并不完全相关,在asp.net中还有一个相关的符号叫做Expression Builder:
<asp:SqlDataSource ... Runat="server"
ConnectionString="<%$ ConnectionStrings:Northwind %>"
/>
<asp:Literal Runat="server"
Text="<%$ Resources:MyResources, MyText %>"
/>
and it's extensible, see http://msdn.microsoft.com/en-us/magazine/cc163849.aspx#S4
它是可扩展的,请参见http://msdn.microsoft.com/en-us/magazine/cc163849.aspx#S4
#5
0
javascript in .aspx that uses a master page.
在.aspx中使用母版页的javascript。
var e = document.getElementById('<%= lblDescription.ClientID %>');
e.innerHTML = 'getElementById(\'lblDescription\') will be null';
#1
18
These are somewhat informally referred to as "bee stings". There are 4 types:
这些被非正式地称为“蜜蜂螫刺”。有四类:
<%# %>
is invoked during the DataBinding phase.
<%# %>在数据库阶段被调用。
<%= %>
is used to get values from code to the UI layer. Meant for backward compatibility with ASP applications. Shouldn't use in .NET.
<%= %>用于从代码获取值到UI层。用于与ASP应用程序向后兼容。不应该在。net中使用。
<%@ %>
represents directives and allow behaviors to be set without resorting to code.
<%@ %>表示指令,允许不通过代码设置行为。
<%: %>
(introduced in ASP.NET 4) is the same as %=
, but with the added functionality of HtmlEncoding the output. The intention is for this to be the default usage (over %=
) to help shield against script injection attacks.
<%: %>(在ASP中引入)。NET 4)与%=相同,但是使用HtmlEncoding的附加功能输出。这样做的目的是作为默认用法(超过%=)来帮助屏蔽脚本注入攻击。
Directives specify settings that are used by the page and user-control compilers when the compilers process ASP.NET Web Forms pages (.aspx files) and user control (.ascx) files.
当编译器处理ASP时,指令指定页面和用户控制编译器使用的设置。NET Web Forms页面(。aspx文件)和用户控制(.ascx)文件。
ASP.NET treats any directive block (<%@ %>) that does not contain an explicit directive name as an @ Page directive (for a page) or as an @ Control directive (for a user control).
ASP。NET将不包含显式指令名的任何指令块(<%@ %>)视为@ Page指令(用于页面)或@ Control指令(用于用户控件)。
@Esteban - Added a msdn link to directives. If you need...more explanation, please let me know.
@Esteban -添加msdn链接到指令。如果你需要…更多的解释,请告诉我。
#2
3
参见http://weblogs.asp.net/leftslipper/archive/2007/06/29/how-asp-net-databinding-deals-with-eval-and-bind-statements.aspx
As Albert says, it's all to do with parsing databinding statements.
正如Albert所说,这一切都与解析数据库语句有关。
#3
2
The # version is used while data binding. <%= is just a simple Response.Write
在数据绑定时使用#版本。<%=只是一个简单的Response.Write
#4
2
Not entirely related to the question, there's another related notation in asp.net called Expression Builder:
与这个问题并不完全相关,在asp.net中还有一个相关的符号叫做Expression Builder:
<asp:SqlDataSource ... Runat="server"
ConnectionString="<%$ ConnectionStrings:Northwind %>"
/>
<asp:Literal Runat="server"
Text="<%$ Resources:MyResources, MyText %>"
/>
and it's extensible, see http://msdn.microsoft.com/en-us/magazine/cc163849.aspx#S4
它是可扩展的,请参见http://msdn.microsoft.com/en-us/magazine/cc163849.aspx#S4
#5
0
javascript in .aspx that uses a master page.
在.aspx中使用母版页的javascript。
var e = document.getElementById('<%= lblDescription.ClientID %>');
e.innerHTML = 'getElementById(\'lblDescription\') will be null';