Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create event handler +=

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...

like image 615
Swag Avatar asked Mar 14 '26 15:03

Swag


1 Answers

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
}
like image 50
Belogix Avatar answered Mar 16 '26 06:03

Belogix



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!