First of all, the main goal of this post is to demonstrate an example of triggering events in Asp.Net.
My asp.net page:
<asp:Button ID="Button1" runat="server"
Text="Button 1" OnClick="Button1_Click" />
<br />
<asp:Button ID="Button2" runat="server" Text="Button 2"
OnClick="Button2_Click" />
<br />
<asp:Button ID="Button3" runat="server" Text="Button 1 and 2"
OnClick="Button3_Click" />
<br />
<asp:Label ID="lbl_output" runat="server" Text=""></asp:Label>
Code Behind:
protected void Page_Load(object sender, EventArgs e)
{
Button3.Click += new EventHandler(Button1_Click);
Button3.Click += new EventHandler(Button2_Click);
}
protected void Button1_Click(object sender, EventArgs e)
{
lbl_output.Text += "Button 1 clicked<br>";
}
protected void Button2_Click(object sender, EventArgs e)
{
lbl_output.Text += "Button 2 clicked<br>";
}
protected void Button3_Click(object sender, EventArgs e)
{
lbl_output.Text += "Button 3 clicked<br>";
}
Output with 3rd button click: