In ASP.Net, what is the difference between <%= x %> and <%# x %>?
Asked
Active
Viewed 1.2k times
4 Answers
73
See this question:
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<%:- Equivalent to<%=, but it also html-encodes the output.
Community
- 1
- 1
Joel Coehoorn
- 380,066
- 110
- 546
- 781
-
Thanks Joel for providing links and a very clear answer. – Jessy Jan 23 '16 at 23:47
5
<%# 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
- 54,910
- 30
- 111
- 164
2
<%= x %> is shorthand for Response.Write()
<%# x %> indicates a databind.
<% %> indicates server-executable code.
Yes - that Jake.
- 16,218
- 14
- 70
- 95