I need to call a javascript function in a Gridview, the javascript function is called display(id)
The id is a parmater which is retrived from the Objectdatasource which is binding my gridview as follows:
<asp:ImageButton ID="imgbut" runat="server" src="/images/gimage.jpg" OnClientClick="display('<%# Eval("id") %>')" />
This code does not work because there are " inside the main " "
and the error message returned is
**
The server tag is not correct
**
Is there a ways to bypass this issue.
2
Answers
Thanks to Albert D.Kallal Answer, I fixed the issue , but I added (") separator before and after the value coming from the database as follaws:
Try it like this:
Code to load is this:
and we get this:
However, I often find such expressions a bit "messsy", so I will often just create out of the blue some custom attribuotes for the button click (or image button click – don’t matter).
So, I might for example do this:
So, it just OH so much less hassle to add some attributes as per above, and now I get this for a click on the image.
Note that I also often do this for server side buttons also.
You can then do this: