I'm building a button in my code behind file and want to bind the click function to an existing click function of a different button. How do I handle this? I was hoping for something simple like:
Button b = new Button();
b.onClick = otherClickEvent();
but apparently that's not doable. Am I missing something here. I'm aware of OnClientClick, but that only deals with the JS side of things apparently.
Button b = new Button();
b.Click += new EventHandler(b_Click);
and later on the page
private void b_Click(object sender, EventArgs e)
{
your code
}
b.OnClick += otherClickEvent;
To add event handlers in C#, use +=
. To remove them, use -=
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With