<%$, <%@, <%=, <%# … what&#39;s the deal?

强颜欢笑 提交于 2019-11-26 01:09:51

问题


I\'ve programmed in both classic ASP and ASP.NET, and I see different tags inside of the markup for server side code.

I\'ve recently come across a good blog on MSDN that goes over the difference between:

  • <%= (percentage together with equals sign) and
  • <%# (percent sign and hash/pound/octothorpe)

(<%# is evaluated only at databind, and <%= is evaluated at render), but I also see:

  • <%$ (percent and dollar sign) and
  • <%@ (percent sign and at symbol).

I believe <%@ loads things like assemblies and perhaps <%$ loads things from config files? I\'m not too sure.

I was just wondering if anyone could clarify all of this for me and possibly explain why it\'s important to create so many different tags that seemingly have a similar purpose?


回答1:


  • <% %> - is for inline code (especially logic flow)
  • <%$ %> - is for evaluating expressions (like resource variables)
  • <%@ %> - is for Page directives, registering assemblies, importing namespaces, etc.
  • <%= %> - is short-hand for Response.Write (discussed here)
  • <%# %> - is used for data binding expressions.
  • <%: %> - is short-hand for Response.Write(Server.HTMLEncode()) ASP.net 4.0+
  • <%#: %> - is used for data binding expressions and is automatically HTMLEncoded.
  • <%-- --%> - is for server-side comments



回答2:


You've covered 2 of them (<%# is evaluated only at databind, and <%= is evaluated at render), and the answer for "<%@" is that it's compiler directives (ie., stuff like what you'd put on a compiler's command line).

I don't know about "<%$".



来源:https://stackoverflow.com/questions/957284/whats-the-deal

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!