ASP.NET Events and dynamic controls

Discussion in 'ASP .Net' started by Kenton Smeltzer, Oct 22, 2003.

  1. Hello All,

    I am having a problem with events and the addition of
    controls on a page I am developing. First let me tell you
    what I have tried and then maybe someone can see something
    I missed.

    First I tried adding the controls and the event handlers
    for my control in the Initialize Components method of my
    page in the hopes that it would fire the event before the
    Page_Load method was called but to no avail. It seems that
    ASP.NET will not let you handle events before the page is
    loaded which is expected but it was worth a shot.

    Second I decided to go ahead and add my controls and the
    event handlers in the Page_Load method and then add the
    new controls as the event fired and then push everything
    into the control collection at the OnPreRender this worked
    as expected and the events fired before the PreRender the
    only problem is that any new control added at PreRender
    does not maintain its state. Textboxes loose there text
    and any handlers attached to the control loose reference
    to the delegate they where pointing to. Anyway I need to
    find some way to add controls to the control collection
    dynamically and get them down to the browser. Right now I
    have a real nasty method that just clears all child
    controls and calls the Page_Load again and then when
    Page_Load creates the control it calls a delegate to give
    the control that launched it a handle to it. But there has
    got to be a better way.

    How can I get these controls added before the page is
    render and get them to keep their state information.

    Thanks,
    Kenton
     
    Kenton Smeltzer, Oct 22, 2003
    #1
    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. Replies:
    5
    Views:
    5,598
  2. Ronald
    Replies:
    2
    Views:
    860
    Robbe Morris [C# MVP]
    Jan 17, 2006
  3. newbye
    Replies:
    0
    Views:
    586
    newbye
    Jul 6, 2006
  4. dje

    dynamic events on dynamic controls

    dje, Jun 25, 2004, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    131
    Robert Koritnik
    Jun 28, 2004
  5. Chris

    Events Events Events Please Help

    Chris, Aug 30, 2005, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    387
    Chris
    Aug 30, 2005
Loading...

Share This Page