Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between <%= %> and <%# %>?

I tried to find what the difference is between these two with Google, but I could not find an exact definition, and I could not exactly search for symbols either.

Right now I know that you can put a piece of code between <%# %> and you have to call Page.DataBind() method to apply it, I think this is how <%# %> works. But what does <%= %> mean? When should I use it?

like image 217
NomenNescio Avatar asked Oct 21 '11 07:10

NomenNescio


1 Answers

The Basic differences are:

The <%= %> expressions are evaluated at render time.

The <%# %> expressions are evaluated at DataBind() time and are not evaluated at all if DataBind() is not called.

<%# %> expressions can be used as properties in server-side controls.

<%= %> expressions cannot and are used to reference properties or fields.

For example:

<%= Response.Write() %>

<ItemTemplate>
      <%# DataBinder.Eval("Title") %>
</ItemTemplate>

You can have a more detailed explanation on msdn here: What's the difference between <%= %> and <%# %>

Hope this helps.

like image 77
AlphaMale Avatar answered Sep 20 '22 13:09

AlphaMale