Sarah
Sarah

Reputation:

ASP.NET embedded code expressions

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.

Upvotes: 0

Views: 2162

Answers (3)

Damien McGivern
Damien McGivern

Reputation: 4004

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.

Upvotes: 0

Sarah
Sarah

Reputation:

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?

Upvotes: 1

eglasius
eglasius

Reputation: 36035

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

Upvotes: 0

Related Questions