On the UI, I've got this:
It's a div inside a Gridview with a JSON string inside of it, and next to it is an icon that I want to use as a "copy to clipboard". I already have the CopyToClipBoard javascript method, and it works fine. What I'm having trouble with is getting the json string inside of the onclick method. Some things I've tried:
onclick='copyToClipboard("<%# Eval("LogText")%>")'
onclick="copyToClipboard('<%# Eval("LogText")%>')"
And all of the suggestions on this thread:
Passing Eval from ASPX to Javascript function as Parameter
Here's the full JSON string:
{
"DoorId": "11574544",
"DoorName": "out - door controller",
"CardNumber": "65529",
"FacilityCode": null,
"EventID": "570924d6-94b4-45b4-aa2d-9ab4075dc668",
"EventTimestamp": "2017-11-10 11:10:10.301",
"Name": "Norman Bates",
"AccessControlUserId": "15531926",
"OrganizationSys": 1012,
"AccessGranted": true,
"FirstName": "Norman",
"LastName": "Bates",
"Email": null,
"UserName": "normanbates",
"Password": "Password",
"Pin": null,
"CreateUserIfNotExists": false,
"CreateDoorIfNotExists": true,
"DoorStatusSys": 476,
"DoorLocationSys": 103979,
"AccessIntegrationSys": 100001
}
The problem is that all of the quotes seem to be messing things up. At least I think. For example, with this:
onclick='copyToClipboard("<%# Eval("LogText")%>")'
I get this:
<img src="..." onclick="copyToClipboard("{"DoorId":"11574544","DoorName":"out - door controller","CardNumber":"65529","FacilityCode":null,"EventID":"570924d6-94b4-45b4-aa2d-9ab4075dc668","EventTimestamp":"2017-11-10 11:10:10.301","Name":"Norman Bates","AccessControlUserId":"15531926","OrganizationSys":1012,"AccessGranted":true,"FirstName":"Norman","LastName":"Bates","Email":null,"UserName":"normanbates","Password":"Password","Pin":null,"CreateUserIfNotExists":false,"CreateDoorIfNotExists":true,"DoorStatusSys":476,"DoorLocationSys":103979,"AccessIntegrationSys":100001}")">
When I click on the icon, I get this in the console:
Uncaught SyntaxError: missing ) after argument list
Not sure how to get this right.
