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. Advertising

  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. Advertising

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. =?Utf-8?B?cmFq?=
    Replies:
    0
    Views:
    1,502
    =?Utf-8?B?cmFq?=
    Apr 12, 2005
  2. Replies:
    0
    Views:
    370
  3. msimmons
    Replies:
    0
    Views:
    550
    msimmons
    Jul 16, 2009
  4. teddy
    Replies:
    2
    Views:
    130
    Corbin
    May 7, 2004
  5. 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:
    166
    news.microsoft.com
    Oct 21, 2004
Loading...

Share This Page