“特殊”ASP的官方名称是什么?NET标签是这样的:

<%# %>
<%= %>
<%@ %>
<%$ %>

我似乎不知道这些概念上或众所周知的名称,所以我在搜索更多信息时遇到了麻烦。作为额外的奖励,谁能给我一个所有可能的“特殊标签”的快速概述,以及每个标签的功能(或指向资源)?


当前回答

你的名字问题没有答案,但MSDN“ASP。NET Page Syntax”的页面相当不错(或者更确切地说,这是顶级页面;下面的页面提供了更多的信息)。

编辑:我之前认为<%#…%>没有包含在列表中,但是在数据绑定表达式下,它当然包含在列表中。哎。

其他回答

我也听说过这些叫做“V刺”,包括在StackOverflow Podcast上。

你的名字问题没有答案,但MSDN“ASP。NET Page Syntax”的页面相当不错(或者更确切地说,这是顶级页面;下面的页面提供了更多的信息)。

编辑:我之前认为<%#…%>没有包含在列表中,但是在数据绑定表达式下,它当然包含在列表中。哎。

它的正式名称是“服务器端脚本定界符”或“ASP。NET内联表达式”。Visual Studio 2008语法高亮设置对话框称这些为“HTML服务器端脚本”。微软的人在他们的博客中称之为“代码块”。

<%@ %> is a Directive for ASP.NET Web Pages. Used for pages and controls to configure page/control compiler settings (<%@ Control Inherits="MyParentControl" %>). <%@ %> is also an Application Directive. Used to specify application-specific settings for global.asax. Distinct from the page directives as it only uses a different tag set. <% %> is a Code Render Block (for inline code). One of 4 forms of Embedded Code Blocks. Used for inclusion of server-side code to the Render() method (<% x = x + 1; %>) of the generated class. Format: single/multiline or multiple-linked (e.g. if/then/else interspersed with html) but cannot be used to declare functions. <%= %> is a Code Render Block (for inline expressions). Used as a shorthand for <%Response.Write(value)%> <%: %> (unofficially an "Html Encoding Code Block") is the same as previous, but the output is HTML encoded. <%# %> is a Data-binding Expression. Used for one-way (readonly) or two-way (updateable) binding through Eval, Xpath, Bind, or expressions (e.g. the selected value of a drop-down control). Binds expressions to data-bound control properties through the control's attribute markup, or as a separate tag which generates a DataBoundLiteralControl instance with the value on its Text property. Expressions are evaluated by a DataBinding event handler for the control. <%#: %> is an HTML Encoded Data-Binding Expression (new in ASP.NET 4.5). It combines the functionality of <%# %> and <%: %>. <%$ %> is an ASP.NET Expression Builder. Used for runtime expression binding for control properties through the server tag attributes. Used with AppSettings, ConnectionStrings, or Resources (or your own custom extension, for example to use code-behind properties). These assignments are added to the OnInit() method of the generated class. <%-- --%> is a Server-Side Comment. Used to exclude the contents from compilation (and so will generate errors if a commented-out control is referred to in code-behind). Unlike html comments the contents will not be included in the output. <!-- #Include ... --> is a Server-Side Include Directive. Used to insert the contents of a file into the page, control or global file. Useful where a user control is overkill, and a master page cannot be used.

还有一个代码声明块,即最终的嵌入式代码块形式。

<script runat="server">
bool IsTrue() {
  return false;
}
</script>

这用于将额外的成员(方法等)包含到从ASP生成的类中。净的标记。它们的提供只是“主要是为了保持与旧ASP技术的向后兼容性”,不建议使用。

每当我对服务器端语法有疑问时,我总是发现这个快速入门页面非常有用。它详细介绍了8种不同的标记样式,并提供了每种样式的说明性示例,此外还解释了它们的优缺点。

不过,它没有提到Page级指令,IIRC在《快速入门》的其他地方详细介绍了这一点。

当然,这与ASP有关。NET 2.0。

微软的人有时称之为“鸡块”或“代码鸡块”。