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?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
<%= 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.
Method 2
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.
Method 3
<%= is shorthand for Response.Write().
<%# indicates that you’re working with the data container in a data bound control.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0