In ASP.Net, what is the difference between <%= x %> and <%# x %>?
Asked
Active
Viewed 1.3k times
4 Answers
76
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
- 399,467
- 113
- 570
- 794
-
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
- 56,753
- 31
- 116
- 165
2
<%= x %> is shorthand for Response.Write()
<%# x %> indicates a databind.
<% %> indicates server-executable code.
Yes - that Jake.
- 16,725
- 14
- 70
- 96