Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When should I use # and = in ASP.NET controls?

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 687
y0mbo Avatar asked Sep 22 '08 14:09

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 148
Keith Avatar answered Oct 04 '22 05:10

Keith