Forcely call button click event in from another button's click event

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

<html xmlns="">
<head runat="server">
<title>Testing Page</title>
<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" />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<br /><br />
<asp:Button ID="Button2" runat="server" Text="Button 2" OnClick="Button2_Click" />
<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>

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