Re: How to add click function to a dynamically created Button in WebForm application?

From: Aaron Bertrand - MVP (aaron_at_TRASHaspfaq.com)
Date: 05/05/04


Date: Wed, 5 May 2004 14:52:47 -0400

http://www.aspfaq.com/5002

-- 
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/
"teddy" <teddy@ee.columbia.edu> wrote in message
news:c7bcoh$c2$1@newsmaster.cc.columbia.edu...
>
> 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,
>