代码之家  ›  专栏  ›  技术社区  ›  pencilCake

你能说出<%=%>、<%#%>和<%$%>之间的区别吗ASP.NET表达?

  •  11
  • pencilCake  · 技术社区  · 15 年前

    你能简单地列举一下两者的区别吗 <%= %> <%# %> <%$ %> 举个简单的例子?

    1 回复  |  直到 9 年前
        1
  •  22
  •   TheCloudlessSky    15 年前

    <%%>

    <% this.CallMethod() %> - Basic code block 执行里面的语句。


    <%=%>

    <%= "text" %> Embedded code syntax . 和写作一样 <% Response.Write("text") %> .


    <

    <%: "text" %> -和上面一样,只是它是 <%= Server.HtmlEncode("text") %> . 这是 introduced in ASP.NET 4


    <%#%>

    <%# Eval("ColumnName") %> -用于 databinding .


    <%$%>

    <%$ AppSettings: settingName %> expression syntax 具有前缀,例如 AppSettings , ConnectionStrings ,或 Resources 然后是一个 : create your own syntax 在这里使用(谢谢@Thomas Levesque)。阿尔索 see MSDN


    <%@%>

    <%@ Page language="C#" %> -那个 directive syntax 对页/控件设置有用。


    <%-----%>

    <%-- This is a comment --%> - Server-side comment 语法。这与HTML不同 <!-- a comment --> 它的语法 不会