Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.net: What is the difference between <%, <%= and <%#? [duplicate]

I have been using ASP.NET for years, but I can never remember when using the # and = are appropriate.

For example:

<%= Grid.ClientID %>

or

<%# Eval("FullName")%>

Can someone explain when each should be used so I can keep it straight in my mind? Is # only used in controls that support databinding?

like image 498
y0mbo Avatar asked Dec 29 '25 13:12

y0mbo


1 Answers

There are a couple of different 'bee-stings':

  • <%@ - page directive
  • <%$ - resource access
  • <%= - explicit output to page
  • <%# - data binding
  • <%-- - server side comment block

Also new in ASP.Net 4:

  • <%: - writes out to the page, but with HTML encoded

Also new in ASP.Net 4.5:

  • <%#: - HTML encoded data binding
like image 200
Keith Avatar answered Dec 31 '25 01:12

Keith



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!