Surya sasidhar
Surya sasidhar

Reputation: 30343

how to create dynamic controls and events?

i created a dynamic control but i want to create events dynamically for the control for example button i created a dynamic button like.

    Button btn = new Button();       
    btn.Text = "click";       
    form1.Controls.Add(btn);

Upvotes: 0

Views: 598

Answers (2)

AB Vyas
AB Vyas

Reputation: 2389

but = new Button(); but.Click += new EventHandler(this.button_Click); form1.Controls.Add(but);

Upvotes: 0

treaschf
treaschf

Reputation: 5944

You can do it in the Init event of the page, by simply setting the btn.Clicked event to the appropriate delegate.

btn.Clicked += this.btnClickedEventHandler;

Upvotes: 2

Related Questions