Forcely call button click event in asp.net from another button's click event

Ranjeet_8
Posted by Ranjeet_8 under ASP.NET category on | Points: 40 | Views : 10924
Below is the ASPX design page.

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Testing Page</title>
</head>
<body>
<form id="form1" runat="server">
Click on Button 1 to fire both click event.<br />
<asp:Button ID="Button1" runat="server" Text="Button 1" OnClick="Button1_Click" />
&nbsp;
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<br /><br />
<asp:Button ID="Button2" runat="server" Text="Button 2" OnClick="Button2_Click" />
&nbsp;
<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
</form>
</body>
</html>

Below is the C# Code.

protected void Button1_Click(object sender, EventArgs e)
{
Label1.Text = "Button 1 Pressed...";
Button2_Click(this, EventArgs.Empty);
}
protected void Button2_Click(object sender, EventArgs e)
{
Label2.Text = "Button 2 Pressed...";
}

Comments or Responses

Login to post response