1

I'm working on various asp.net pages .

For inline functions I do see 2 different formats are used:

Example 1:

<p><%Response.Write(now())%></p>

I also see another one with #:

Example 2:

<Asp:TextBox id="Textbox5" width="40" Text='<%# DataBinder.Eval(Container.DataItem, "Name") %>' runat="server" />

I want to know what is the exact different , <%# vs <%

It'sNotALie.
  • 22,289
  • 12
  • 68
  • 103
  • How did you guys found the duplicates??? I wonder when I was asking this question , those duplicates did Not show under "Questions that may already have your answer" I also did a search but no similar results. –  Jul 17 '13 at 16:06
  • please comment on above... –  Jul 17 '13 at 16:07
  • Give it a try Search for <%# vs <% no related results. Search for <%# no results!!! –  Jul 17 '13 at 16:10
  • Anyway Thank for quick answers. –  Jul 17 '13 at 16:12
  • No big deal about not seeing existing answers to your question. I had the post I linked bookmarked. I think I stumbled onto it from google not that long ago. It's good to see answers on stackoverflow show up at the top of your search results on google. – Ross Jul 17 '13 at 16:21
  • I found it by searching google for "ASP.net code blocks". searching for symbols is very difficult. – Jason P Jul 17 '13 at 16:37

2 Answers2

4

Here is a good explanation here on stack -

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

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.
Community
  • 1
  • 1
Ross
  • 3,335
  • 1
  • 19
  • 18
  • Very nice reference. I wonder when I was asking this question , those duplicates did Not show under "Questions that may already have your answer" –  Jul 17 '13 at 16:04
3

The former is simply denotes some .NET code in the markup that outputs to the page.

The later uses Data Binding Expression Syntax to bind to a specific object.

Justin Niessner
  • 242,243
  • 40
  • 408
  • 536