Capturing event from other custom control within another custom control

Discussion in 'ASP .Net Web Controls' started by Jonah Olsson, Apr 5, 2005.

  1. Jonah Olsson

    Jonah Olsson Guest

    Hello,

    I'm trying to build an "add-on" to an already existing custom web user
    control. The old control collects some user data and saves it to a database.
    The new control should collect some extra info from the user and add it to a
    new table in the database.

    The old control should not be re-written (at least not now..), so I need a
    way of capturing the click event of the Save button in the old control. This
    event should trigger a function in the new control that saves the "add-on"
    data.

    Both controls are being added to the page at run-time and has the save level
    (the new control is no child control to the old one).

    Correct me if I'm wrong, but I can't use bubbling events since the new
    control isn't a child control to the old control, right?

    What should I do?

    Thanks for any help!

    Regards,
    Jonah Olsson
    Jonah Olsson, Apr 5, 2005
    #1
    1. Advertising

  2. Jonah Olsson

    Brock Allen Guest

    > The old control should not be re-written (at least not now..), so I
    > need a way of capturing the click event of the Save button in the old
    > control. This event should trigger a function in the new control that
    > saves the "add-on" data.


    Normally you shouldn't be handling events owned by another control. Typically
    the custom control should raise its own events to publicize that something
    has happened. So, the right approach would be to modify the custom control
    to raise its own events.

    Now, having said that, you could still probably make it work without modifying
    the custom control. You just need to locate the Button control in the custom
    control and handle its Click event. Event control has a collection of child
    controls, so I could image some really ugly code to iterate over the child
    controls collection of the custom control until the Button is located. Once
    you have that reference then you should be all set.

    -Brock
    DevelopMentor
    http://staff.develop.com/ballen



    > Hello,
    >
    > I'm trying to build an "add-on" to an already existing custom web user
    > control. The old control collects some user data and saves it to a
    > database. The new control should collect some extra info from the user
    > and add it to a new table in the database.
    >
    > The old control should not be re-written (at least not now..), so I
    > need a way of capturing the click event of the Save button in the old
    > control. This event should trigger a function in the new control that
    > saves the "add-on" data.
    >
    > Both controls are being added to the page at run-time and has the save
    > level (the new control is no child control to the old one).
    >
    > Correct me if I'm wrong, but I can't use bubbling events since the new
    > control isn't a child control to the old control, right?
    >
    > What should I do?
    >
    > Thanks for any help!
    >
    > Regards,
    > Jonah Olsson
    Brock Allen, Apr 5, 2005
    #2
    1. Advertising

  3. Jonah Olsson

    Jonah Olsson Guest

    Hi Brock and thanks for your reply!

    I know this is not a nice way of solving the problem, but unfortunately it's
    the only idea I had to make the new control "listen" to the old one since we
    can't make changes to the old control at the moment :-(

    Thanks,
    Jonah
    Jonah Olsson, Apr 5, 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. sqlboy2000
    Replies:
    0
    Views:
    369
    sqlboy2000
    Nov 24, 2003
  2. Jonah Olsson
    Replies:
    1
    Views:
    562
    Scott Allen
    Apr 5, 2005
  3. Chu
    Replies:
    2
    Views:
    893
    Winista
    Apr 10, 2006
  4. Matt Sokol
    Replies:
    2
    Views:
    365
    Theo Tillotson
    Aug 7, 2003
  5. Ralph Krausse
    Replies:
    1
    Views:
    209
    John Saunders
    Sep 15, 2004
Loading...

Share This Page