views:

285

answers:

3

While editing an aspx file I found both these opening tags used for seemingly the same thing. Is there a difference and if yes, what is it?

+1  A: 

The difference is that the # symbol specifies a data binding directive, that is resolved at data binding time (for example, when you call Page.DataBind ) and the = sign specifies an evaluation expression just evaluates and prints to the HTML output when that line is processed.

Edit: Just adding that only inside <%# %> you have acces to databinding functions like Eval.

Sergio Acosta
+12  A: 

<%= is a equivalent to <% Repsonse.Write()

You can write any content out here: for example

<%=myProperty + " additional Text" %>

<%# is a binding expression. You can retrieve any public value in the current context (for example in GridViews). But you cannot mix content here.

Take a look at MSDN for more information.

Johannes Hädrich
Ahh, I was wondering why <%= always caused my writes to be written out of sync with the output stream... Have been using labels instead. Thanks.
tsilb
+1  A: 

<%= is shorthand for Response.Write().
<%# indicates that you're working with the data container in a data bound control.

Andrew Myhre