Reputation: 13927
I have a DataGrid template that correctly outputs a picture of a phone in each of my rows. When the user clicks the phone, I would like to display the phone number to the user, either through an alert box or through a jquery dialog.
I currently have:
<asp:ImageButton runat="server" ImageUrl="~/img/Phone.jpg"
ID="imgDist_Phone"
OnClientClick="
alertPhoneNumber('<%# DataBinder.Eval(Container.DataItem, "PhoneNumber") %>')
" />
Obviously this doesn't work because it outputs <%# DataBinder
literally.
What is the best way to generate the onClick event dynamically, so that I don't have to postBack to the server?
Upvotes: 1
Views: 2616
Reputation: 5825
Try this
<asp:ImageButton runat="server" ImageUrl="~/img/Phone.jpg"
ID="imgDist_Phone"
OnClientClick='<%# string.Format( "alertPhoneNumber( \"{0}\" );", DataBinder.Eval(Container.DataItem, "PhoneNumber") ) %>' />
Should be close on the syntax
Upvotes: 4