0

The below code works but I am not sure how?

OnClientClick='<%# CreateConfirmation(Eval("EventName"),DataBinder.Eval(Container.DataItem, "EventDate", "{0:ddd, d MMM}")) %>'

Public Function CreateConfirmation(ByVal EventName As String, ByVal EventDate As String) As String Return String.Format("return confirm('Are you sure you wish to register for {0} on {1} ?');", EventName, EventDate) End Function

I have read that <%# %> is a databinding expression, but overhere we are not directly data-bidning (infact returining value from the function CreateConfirmation) and I also thought that it should work with <%= %> but it gives JavaScript error message i.e. Illigal XML character pointing to =

Please could you clarify as to why is this?

Many Thanks.

3 Answers3

1

This question is very precisely answered in an exisiting post:

Why will <%= %> expressions as property values on a server-controls lead to a compile errors?

Community
  • 1
  • 1
0

You can call any code inside the <%#. The Eval bit is the piece that makes it relate to the row/object in the datasource.

eglasius
  • 35,831
  • 5
  • 65
  • 110
0

You are still binding the returned string to the property. You can only use <%=%> with inline HTML. You have to use <%#%> when binding to a contols property.

Damien McGivern
  • 3,954
  • 3
  • 27
  • 21