2

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.
  • 21,548
  • 11
  • 66
  • 101
Joe Tatavaran
  • 305
  • 2
  • 8

2 Answers2

5

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,325
  • 1
  • 18
  • 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" – Joe Tatavaran Jul 17 '13 at 16:04
4

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
  • 236,029
  • 38
  • 403
  • 530