Is it possible to call a server side buttons click event using javascript or jquery If yes then how to do it
-
3What do you mean by "server side button"? – Anthony Grist Jan 04 '13 at 11:31
-
1There is no "server side buttons click event" im aware of – A. Wolff Jan 04 '13 at 11:32
-
If you are on asp.net, you should use `onclientclick` instead of `onclick`. – Mr_Green Jan 04 '13 at 11:33
-
I have no idea what are you talking about (server side button?!) but you could check the jquery click to see if it's what you're looking for: http://api.jquery.com/click/ – sica07 Jan 04 '13 at 11:34
7 Answers
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();

- 12,081
- 22
- 83
- 117
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>

- 7,782
- 2
- 24
- 31
-
This works well!! Can we hide the visibility of the ASP button ? Here no need of handle the button event twice. – Prajwal Bhat Jun 26 '17 at 12:46
in jquery
$("#button_id").click(function(){
// do something when button is clicked
});
and invoke the function with
$("#button_id").click();

- 8,019
- 1
- 40
- 43
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

- 2,643
- 2
- 17
- 25
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();

- 1,060
- 10
- 20
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.

- 6,664
- 35
- 100
- 166