Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between the <%# and <%= opening tags?

Tags:

.net

asp.net

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?

like image 241
sebastiaan Avatar asked Sep 19 '08 10:09

sebastiaan


People also ask

What is the significance of <%! In JSP?

%> is used to embed some java code within the main service() method of the JSP. It is executed during the rendering of the page. <%! ... %> is used to define code outside of the flow of the page, and therefore outside the main service() method.

What is difference between. net and asp net and MVC?

The main difference between ASP.NET Core and ASP.NET MVC 5 is their cross-platform approach. ASP.NET Core can be used on Windows, Mac, or Linux, whereas ASP.NET MVC 5 can only be used for applications on Windows. The ASP.NET Core MVC is a framework for building web apps and APIs, optimized for use with ASP.NET Core.


2 Answers

<%= 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.

like image 64
Johannes Hädrich Avatar answered Sep 29 '22 23:09

Johannes Hädrich


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.

like image 22
Sergio Acosta Avatar answered Sep 30 '22 01:09

Sergio Acosta