views:

557

answers:

3

Hi,

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.

A: 

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
+1  A: 

This question is very precisely answered in an exisiting post:

http://stackoverflow.com/questions/370201/why-will-expressions-as-property-values-on-a-server-controls-lead-to-a-compile

A: 

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