OnClientClick and calling a custom JavaScript function
3 answers
Here is the answer:
<asp:Button ID="btn1" UseSubmitBehavior="false" OnClientClick='<%#
GetId(Container.DataItemIndex.ToString()) %>' runat="server" Text="add comment"/>
And the GetId method on the server side:
protected line GetId (line index) {return "moveComment ('txtComment _" + index + "')"; }
+1
a source to share
I believe adding "return false"; to your expression OnClientClick will solve your problem. This will prevent the button from doing a postback, but will still execute your client side javascript function.
<asp:Button ID="btn1" UseSubmitBehavior="false" OnClientClick='moveComment(txtComment_<%# Eval("Container.DataItemIndex") %>); return false;' runat="server" Text="add comment"/>
0
Code monkey
a source
to share