In ASP.Net, what is the difference between <%= x %>
and <%# x %>
?
views:
346answers:
4
+2
A:
<%#
is data binding expression syntax.
<%=
resolves the expression returns its value to the block (Embedded code block reference) - effectively shorthand for <% Response.Write(...); %>
Daniel Schaffer
2009-02-05 20:21:20
+1
A:
<%# is the databinding directive, <%= is a shortcut for "Response.Write"
BC
2009-02-05 20:21:56
+12
A:
See this question:
http://stackoverflow.com/questions/115159/when-should-i-use-and-in-asp-net-controls
Summary from those answers:
There are a several different 'bee-stings':
<%@
- Page/Control/Import/Register directive<%$
- Resource access and Expression building<%=
- Explicit output to page, equivalent to<% Response.Write( ) %>
<%#
- Data Binding. It can only used where databinding is supported, or at the page level if you callPage.DataBind()
in your code-behind.<%
-- - Server-side comment block
Joel Coehoorn
2009-02-05 20:22:46
+1
A:
<%= x %> is shorthand for Response.Write()
<%# x %> indicates a databind.
<% %> indicates server-executable code.
Jekke
2009-02-05 20:23:33