Alex Rivera | Logout

How can I create a dynamic button click event on a dynamic button?

Asked 2011-05-31T13:00:26.103
47

I am creating one button on a page dynamically. Now I want to use the button click event on that button.

How can I do this in C# ASP.NET?

Edit
Report

1 Answer

43

The easier one for newbies:

Button button = new Button();
button.Click += new EventHandler(button_Click);

protected void button_Click (object sender, EventArgs e)
{
    Button button = sender as Button;
    // identify which button was clicked and perform necessary actions
}
answered 2011-05-31T13:11:31.503

Your Answer