I am using this on my webform, to create dynamic buttons.
Button b1 = new Button();
I would like to get this:
b1.Click+=new EventHandler(OnClick);
How can I do this? I want that the event is created automatically, it could be done with pressing twice tab or something, but I forgot it...
If you mean you want to know the signature for OnClick it would be:
public void CreateDynamicButtons()
{
Button b1 = new Button();
b1.Click += new EventHandler(OnClick);
// Or you could simply do
Button b2 = new Button();
b2.Click += OnClick;
}
protected void OnClick(Object sender, EventArgs e)
{
// This is called when b1 or b2 are clicked
}
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