.net - <%# %> 和 <%= %> 有什么区别?

标签 .net asp.net

请原谅我对 ASP 的无知,但有什么区别?

最佳答案

这些在某种程度上被非正式地称为“蜜蜂蜇伤”。有4种类型:
<%# %>在 DataBinding 阶段调用。
<%= %>用于从代码获取值到 UI 层。旨在向后兼容 ASP 应用程序。不应该在 .NET 中使用。
<%@ %>代表directives并允许在不借助代码的情况下设置行为。
<%: %> (在 ASP.NET 4 中引入)与 %= 相同,但增加了 HtmlEncoding 输出的功能。目的是将此作为默认用法(超过 %=),以帮助屏蔽脚本注入(inject)攻击。

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 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).



@Esteban - 添加了一个指向指令的 msdn 链接。如果您需要...更多解释,请告诉我。

关于.net - <%# %> 和 <%= %> 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/160097/

相关文章:

c# - 使用哪个 linq 在当前集合中的集合中进行集合搜索

c# - 创建 EntityObject 子类的浅拷贝/克隆

c# - DataView过滤后如何获取数据?

c# - ASP.NET 当单选按钮列表中选定的索引发生变化时如何调用我的函数而不更新整个页面?

asp.net treeview 使用 javascript 选择节点值

c# - 需要 ClassInterfaceType.None 吗?

c# - 可选参数代码在 .NET 3.5 中编译。为什么?

c# - 哪个线程最先进入临界区?

c# - 在登录表单页面上加载 javascript/css?

asp.net - 相当于 ASP.NET 5 中的 RouteData.GetRequiredString