Dynamically adding events to a page

Discussion in 'ASP .Net' started by Oddball, Aug 4, 2005.

  1. Oddball

    Oddball Guest

    I am trying to create and add a number of ImageButtons to a page when a certain
    event is called.

    Not only am I suffering from my page running the "Page_Load" event three times, but I
    can't seem to get my new buttons to fire their events.

    http://www.adquiesco.com/ShowCollection.aspx?collection=4

    As far as I can tell the problem has something to do with the point in the page
    execution where events are wired up.

    Because the "more images" buttons are created and added to the page during an
    event call (unlike the piece images at the bottom which are added on Page_Load) their
    events don't seem to fire.

    I think I've coded myself into a knot here and I would be greatful for any advice that
    you can give me about this problem.

    For example - where SHOULD I be creating and adding new controls to a page, and if
    it HAS to be during page load how do I know which button has been clicked. :S

    --> Oddball


    ------------------------------------

    Another unchecked rambeling brought to you by:

    Oddball
    joshua@bf#N0SP4M#wd.co.uk
     
    Oddball, Aug 4, 2005
    #1
    1. Advertising

  2. Oddball

    Stefan Guest

    The easiest way is in the Init event. Add a handler to the Init event
    and add your buttons there.

    If you add them at a later event (Onload or even OnPrerender), the
    buttons show up in your page, but your viewstate will be corrupted,
    which is why your events don't fire on postback
     
    Stefan, Aug 4, 2005
    #2
    1. Advertising

  3. Oddball

    Stefan Guest

    Stefan, Aug 4, 2005
    #3
    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. JezB
    Replies:
    2
    Views:
    4,875
  2. SevDer
    Replies:
    2
    Views:
    1,315
    Walter Wang [MSFT]
    Nov 13, 2007
  3. Chris

    Events Events Events Please Help

    Chris, Aug 30, 2005, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    393
    Chris
    Aug 30, 2005
  4. David

    Adding events dynamically

    David, Jul 19, 2005, in forum: Javascript
    Replies:
    19
    Views:
    227
    Grant Wagner
    Jul 20, 2005
  5. Steve Macleod
    Replies:
    2
    Views:
    153
    Steve Macleod
    May 20, 2006
Loading...

Share This Page