Reputation: 38573
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") ) %>
Upvotes: 3
Views: 3594
Reputation: 56490
<%# 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.
Upvotes: 5