In ASP.Net, what is the difference between <%= and <%# [duplicate]

Solution 1:

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 call Page.DataBind() in your code-behind.
  • <%-- - Server-side comment block
  • <%: - Equivalent to <%=, but it also html-encodes the output.

Solution 2:

<%# is data binding expression syntax.

<%= resolves the expression returns its value to the block (Embedded code block reference) - effectively shorthand for <% Response.Write(...); %>

Solution 3:

<%# is the databinding directive, <%= is a shortcut for "Response.Write"

Solution 4:

<%= x %> is shorthand for Response.Write()

<%# x %> indicates a databind.

<% %> indicates server-executable code.