I have an asp.net button in the gridview footer, and I wanna to call the server-side ASP.NET button event in the client side (JavaScript).
How to do this please code details if possible.
My .aspx:
<FooterTemplate>
<asp:ImageButton ID="ibtn_add" ImageUrl="~/Images/accord_plus.png"
runat="server" OnClick="ibtn_add_Click" />
</FooterTemplate>
I wanna to know how to call the ibtn_add_Click
in the client side.
in the following code:
var isShift = false;
document.onkeyup = function(e)
{ if (e.which == 16) isShift = false; }
document.onkeydown = function(e) {
if (e.which == 16) isShift = true;
if (e.which == 13 && isShift == true) {
//Here I wanna to call ibtn_add_Click
开发者_C百科 return false;
}
}
Note :
The gridview in an update panel, and I execute the JavaScript through:
<asp:ScriptManager ID="ScriptManager1" runat="server">
<Scripts>
<asp:ScriptReference Path="~/Scripts/Shortcut.js" />
</Scripts>
</asp:ScriptManager>
Use OnClientClick
button's attribute.
OnClientClick="ibtn_add_Click()"
MSDN
I think you want something like this ...
if (e.which == 13 && isShift == true)
{
__doPostBack('ibtn_add','OnClick');
return false;
}
You might use ajax and make a call to webservice or web method or you can use or you can use
__doPostBack(‘btntest','OnClick')
or
$('btntest').trigger('click');
chck this link : http://codethatworkedforme.blogspot.com/2011/08/some-tricks-for-asynchronous-postback.html
<asp:ImageButton ID="ibtn_add" ImageUrl="~/Images/accord_plus.png" runat="server" OnClick="ibtn_add_Click" />
This is the problem I have faced but I used only for OnClientClick
精彩评论