Triple Quotes? How do I delimit a databound Javascript string parameter in ASP.NET?
I had recently similar problem and the only way to solve it was to use plain old HTML codes for single ('
) and double quotes ("
).
Source code was total mess of course but it worked.
Try
<a id="aShowHide" onclick='ToggleDisplay("<%# DataBinder.Eval(Container.DataItem, "JobCode") %>");'>Show/Hide</a>
or
<a id="aShowHide" onclick='ToggleDisplay('<%# DataBinder.Eval(Container.DataItem, "JobCode") %>');'>Show/Hide</a>
onclick='javascript:ToggleDisplay("<%# DataBinder.Eval(Container.DataItem, "JobCode")%> "); '
Use like above.
Without the extra quotes around the input string parameter, the Javascript function thinks I'm passing in an integer.
Can you do some rudimentary string function to force JavaScript into changing it into a string? Like
value = value + ""
Try putting the extra text inside the server-side script block and concatenating.
onclick='<%# "ToggleDisplay(""" & DataBinder.Eval(Container.DataItem, "JobCode") & """);" %>'
Edit: I'm pretty sure you could just use double quotes outside the script block as well.
Passing variable to function without single quote or double quote
<html>
<head>
</head>
<body>
<script language="javascript">
function hello(id, bu)
{
alert(id+ bu);
}
</script>
<a href ="javascript:
var x = "12";
var y = "fmo";
hello(x,y)">test</a>
</body>
</html>