Anyname Donotcare
Anyname Donotcare

Reputation: 11393

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

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
        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>

Upvotes: 0

Views: 4280

Answers (4)

Munish
Munish

Reputation: 11

 <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

Upvotes: 1

Neelam
Neelam

Reputation: 1068

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

Upvotes: 1

Glory Raj
Glory Raj

Reputation: 17691

I think you want something like this ...

if (e.which == 13 && isShift == true) 
{ 
    __doPostBack('ibtn_add','OnClick');
    return false; 
} 

Upvotes: 1

Sergey Metlov
Sergey Metlov

Reputation: 26291

Use OnClientClick button's attribute.

OnClientClick="ibtn_add_Click()"

MSDN

Upvotes: 1

Related Questions