This is my first question ever on StackOverFlow…
Hope it’s not silly…
Thanks in advance for your help!!
I want to click multiple buttons on the click of one button using JQuery
Example:
Button-1 calls -> Button-2 AND Button-3
The user should click Button-1 and it should click Button-2 and Button-3.
It should also fire its related Server side click events.
Following is what I tried, but it fires only the btnOne Server event click and not the other two.
Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="PostBackApp.apppages.Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<script src="https://code.jquery.com/jquery-3.6.0.slim.min.js" integrity="sha256-u7e5khyithlIdTpu22PHhENmPcRdFiHRjhAuHcs05RI="
crossorigin="anonymous"></script>
<title></title>
<script type="text/javascript">
$(function () {
$('#btnOne').click(function myfunction() {
one();
$('#btnTwo').click();
$('#btnThree').click();
});
$('#btnTwo').click(function myfunction() {
two();
});
$('#btnThree').click(function myfunction() {
three();
});
});
function one() {
alert('Client Side One was called');
}
function two() {
alert('Client Side Two was called');
}
function three() {
alert('Client Side Three was called');
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="btnOne" Text="1" runat="server" OnClick="btnOne_Click"> </asp:Button>
<asp:Button ID="btnTwo" Text="2" runat="server" OnClick="btnTwo_Click"></asp:Button>
<input type="button" name="btnThree" id="btnThree" value="3" />
</div>
</form>
</body>
</html>
Default.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace PostBackApp.apppages
{
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
bool isPostbck = this.IsPostBack;
}
protected void btnOne_Click(object sender, EventArgs e)
{
ClientScript.RegisterStartupScript(this.GetType(), "Key1", "alert('Server Side One was called');", true);
}
protected void btnTwo_Click(object sender, EventArgs e)
{
ClientScript.RegisterStartupScript(this.GetType(), "Key2", "alert('Server Side Two was called');", true);
}
}
}

