How to add click function to a dynamically created Button in WebFormapplication?

T

teddy

I am trying to create a bookstore WebApplication using c#. I can
display the books (obtained from sql server) on a table in a WebForm.
At the end of each row, I would like to add "add to cart" button.
Therefore, I use

Button bt_add = new Button();
bt_add.Text = "Add to cart";

and put it in a cell which is later placed in each table row. The
Buttons display fine on the WebForm. However, I don't know how to add
the Button_Click function for each of the Button I created since I don't
know the total number of books in advance. Can anyone help me get "add
to cart" button to work?

Note: I try clicking on each Button, the WebForm page loads back to its
original stage (Page_Load function) and my search result is gone.

Thanks,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top