2012-02-22 103 views
5

可能重複:
What's the difference between <%# %> and <%= %>?
<%$, <%@, <%=, <%# … what's the deal?<%:和<%=和<%#在aspx中有什麼區別?

我道歉,如果這是重複的,但它是僵硬難以谷歌。

+0

也http://stackoverflow.com/questions/197047/what-is-the-difference-between-and – Oded 2012-02-22 16:23:50

+0

和http://stackoverflow.com/questions/160097/whats與其他人之間的差異 – 2012-02-22 16:24:01

+0

乾杯,恥辱,你不能使用搜索搜索<%...即使建議列表中沒有這些。你究竟是怎麼找到它們的? :)我會關閉作爲愚蠢 – NibblyPig 2012-02-22 16:25:54

回答

7

<%:是.NET 4.0的新增功能 - 它相當於HttpUtility.HtmlEncode(Response.Write())

<%=較舊,僅代表Response.Write()

<%#binding expression

+0

+1爲相關標籤 – uday 2012-02-22 16:32:50

+0

小修正:Response.Write(HttpUtility.HtmlEncode()) - 先編碼,然後寫入,而不是其他方式:) – nsimeonov 2018-02-13 01:59:59

5

Here's對他們很好的文章。總結:

Page指令

<%@ Page Language="C#" %> 

渲染代碼

<% Response.Write("Hello World!"); %> 

<%= SayHello("Ahmed") %> 

<%: DateTime.Now.ToString() %> 

表達式語法

<%$ ConnectionStrings:ConnStrFromWebConfig %> 

<%$ AppSettings:ValueFromWebConfig %> 

<%$ Resources:Resource, Arabic %> 

<%$ RouteValue:year %> 

<%$ YourExpressionPrefix : Any %> 

數據綁定語法

<%# Eval("Name") %> 

<%# Bind("Name") %> 

<%# XPath ("Name") %> 

註釋服務器

<%-- <asp:Label runat="server" Text="Label"></asp:Label>-- %> 
相關問題