views:

239

answers:

4

I am trying to insert dynamic data into a onclick property for a control the code looks like this

onclick="openRadWindow('<%#Eval("ID";) %>','<%#Eval("ParentObjectID") %>');"

I cant get it to fire and the trouble seems to be the double quotes, what is the correct method on escaping the quotes so that this fires.

A: 

First thing I see is that semi-colon after "ID" - I think that might be causing your problems.

Joe Enos
Thanks , I did not mean to have that there, but I don't have it in the code
Adonis L
+1  A: 

Is the event just not firing or are you getting any javascript errors as well. Also, I would look at the HTML after the page has been rendered and make sure that the server tags are being processed correctly. There are certain uses that cause them not to actually be processed and will remain <%# Eval("ID") %>.

Mike C
A: 

You can do use a format string, like this:

onclick='<%# string.Format("openRadWindow(\"{0}, {1}\");", Eval("ID"), Eval("ParentObjectID")) %>' 
Nick Craver
I get the error Comma, ')', or a valid expression continuation expected.Changing the onclick='<%# to <%= and it loads but it does not get the databind values Thanks
Adonis L
@Adonis - It's been a while since I did anything like this inline, if you replace `\"` with `\\"`, same result?
Nick Craver
@Adonis - Have you checked the rendered HTML to make sure the databind expressions are working correctly?
Mike C
Thanks to all, I got it working with the solution I added to the original post
Adonis L
@Adonis - That would be my preferred method as well, keeps it cleaner overall, you should add this as an answer though, not in the question....you can answer your own question :) None of the other answers will suffice here for a code-behind because no one knows your object structure :)
Nick Craver
@Nick Thanks your response did send me in the right direction
Adonis L
A: 

Thanks to all I was able to get it working correctly using a different method. in the code behind I created a function and in the function I put the following code

Return String.Format("openRadWindow({0},{1});", photo.ID, photo.ParentObjectID)

and in the aspx I added onclick="<%#MyFunction(DirectCast(Container.DataItem,Photo))%>

Adonis L