Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between `<%#` and `<%=` and an asp.net ascx file?

Tags:

asp.net

I understand that <%= is for returning a String

I seem to usually use <%# in my .ascx files.

For example the following works

OnClientClick=<%# String.Format("return confirm('Are you sure you wish to delete barcode ({0})?');", Eval("BARCODE") ) %>

The following does not work

OnClientClick=<%= String.Format("return confirm('Are you sure you wish to delete barcode ({0})?');", Eval("BARCODE") ) %>

like image 257
jax Avatar asked Aug 31 '25 01:08

jax


1 Answers

<%# indicates there's an evaluation function in there that takes in bound data and examines that data for a column or property in the Eval() function. It is specific to data binding in WebForms.

<%= just expects something that can be converted to a string. It will get confused by EVAL()

And finally there's the new

<%@ in MVC - which takes the string input, and Html encodes it to try to avoid XSS.

like image 189
blowdart Avatar answered Sep 02 '25 23:09

blowdart