Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

asp.net

In ASP.Net, what is the difference between <%= x %> and <%# x %>?

like image 341
marshally Avatar asked Feb 05 '09 20:02

marshally


People also ask

What does <% mean in ASP?

It means you're binding some data element.

What is difference between ASP.NET and MVC?

ASP.NET is a web platform. It provides a layer that sits on top of IIS (the web server) which facilitates the creation of web applications and web services. ASP.NET MVC is a framework specifically for building web applications. It sits ontop of ASP.NET and uses APIs provided by ASP.NET.


2 Answers

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.
like image 120
Joel Coehoorn Avatar answered Oct 25 '22 03:10

Joel Coehoorn


<%# is data binding expression syntax.

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

like image 38
Daniel Schaffer Avatar answered Oct 25 '22 03:10

Daniel Schaffer