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

Discussion in 'ASP General' started by teddy, May 5, 2004.

  1. teddy

    teddy Guest

    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,
     
    teddy, May 5, 2004
    #1
    1. Advertisements

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

    http://www.aspfaq.com/5002

    --
    Aaron Bertrand
    SQL Server MVP
    http://www.aspfaq.com/




    "teddy" <> wrote in message
    news:c7bcoh$c2$...
    >
    > 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,
    >
     
    Aaron Bertrand - MVP, May 5, 2004
    #2
    1. Advertisements

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Purvi T
    Replies:
    0
    Views:
    1,125
    Purvi T
    Oct 19, 2004
  2. gce
    Replies:
    2
    Views:
    3,544
  3. =?Utf-8?B?cmFq?=
    Replies:
    0
    Views:
    1,591
    =?Utf-8?B?cmFq?=
    Apr 12, 2005
  4. Replies:
    0
    Views:
    427
  5. Amy
    Replies:
    0
    Views:
    1,248
  6. msimmons
    Replies:
    0
    Views:
    755
    msimmons
    Jul 16, 2009
  7. teddy
    Replies:
    2
    Views:
    179
    Corbin
    May 7, 2004
  8. news.microsoft.com

    removehandler for dynamically created button.click event

    news.microsoft.com, Oct 21, 2004, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    228
    news.microsoft.com
    Oct 21, 2004
Loading...