开发者

how to call a server-side ASP.NET event from the client-side

开发者 https://www.devze.com 2023-04-09 18:01 出处:网络
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).

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

0

精彩评论

暂无评论...
验证码 换一张
取 消