Escape double quotes in asp.net onclick string

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

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

I can't get him to shoot, and the problem seems to be double quotes, what is the correct way to exit quotes so that this works.

+3
source share
4 answers

You can use a format string, for example:

onclick='<%# string.Format("openRadWindow(\"{0}, {1}\");", Eval("ID"), Eval("ParentObjectID")) %>' 
+2
source

javascript. , HTML , , , . , <% # Eval ( "ID" )% > .

+1

Thanks to everyone that I was able to get it to work 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 aspx I added onclick="<%#MyFunction(DirectCast(Container.DataItem,Photo))%>

+1
source

The first thing I see is that the semicolon after the "ID" - I think this can cause problems.

0
source

Source: https://habr.com/ru/post/1754050/


All Articles