Passing Eval parameter to JavaScript function from ASPX file

I try to pass an Eval value like this, but I get syntax errors:

<asp:ImageButton ID="btnOK" OnClientClick='Show("<%#Eval("Title")%>");return false;' runat="server" ImageUrl="Images/icon.gif" /> 
+4
source share
2 answers

Try this instead.

 <asp:ImageButton ID="btnOK" OnClientClick='<%# Eval("Title", "Show({0});return false;") %>' runat="server" ImageUrl="Images/icon.gif" /> 
+6
source

OnClientClick = '<% # String.Format ("Show (' {0} '); return false;", Eval ("title"))%>'

or if you do this in a design view, just add the data binding for the onclientClick property for the imagebutton property as

 String.Format("Show('{0}');return false;",Eval("title")) 

Hope this helps you.

0
source

All Articles