10

Is it possible to call a server side buttons click event using javascript or jquery If yes then how to do it

Mxyk
  • 10,678
  • 16
  • 57
  • 76
vidyasagar85
  • 131
  • 1
  • 2
  • 11

7 Answers7

17

Lets say this is your html:

<input type="button" id="button" value="btn" />

In jquery, you invoke click of button as below:

$("#button").click();   //button is id

And in javascript:

document.getElementById("button").click();
Ashwin
  • 12,081
  • 22
  • 83
  • 117
4

Yes, javascript can do that. I assume you are using ASP.Net

<asp:Button ID="button" runat="server" Text="Test" />

<script>
    document.getElementById("<%= button.ClientID %>").click();
</script>
phnkha
  • 7,782
  • 2
  • 24
  • 31
4

in jquery

$("#button_id").click(function(){
// do something when button is clicked
});

and invoke the function with

$("#button_id").click();
shweta
  • 8,019
  • 1
  • 40
  • 43
2
document.getElementById("Button1").click();
Azzy
  • 433
  • 2
  • 18
1

call the click() of specified button which will trigger server side events too in web forms.

$("#idofbutton").click(); // whereever required to trigger the server click  event

Thanks

Sridhar Narasimhan
  • 2,643
  • 2
  • 17
  • 25
0

Whether it is a server side control or client side control when the click is triggered in client, based on the attributes it will formulate the server events. Consider an Serverside button from asp.net page, when you trigger click event from javascript/jquery, normally it will make a postback event to the server because of the attribute runat=server. Below is the syntax for triggering the click event in jQuery.

$('#buttonID').click();
Brune
  • 1,060
  • 10
  • 20
0

yes, you can do it with the following code:

$('[id$=txtDOB]').live('blur', function (e) {
        $('[id$=btnsubmit]').click();
    });

The button's click fire on textbox(txtDOB)'s blur event. Hope this will help you.

Ram Singh
  • 6,664
  • 35
  • 100
  • 166