Results 1 to 6 of 6

Thread: Dynamically-created-controls Event firing problem

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2000
    Location
    Europe, Lithuania
    Posts
    309

    Dynamically-created-controls Event firing problem

    Hey,

    I create controls (Texboxes and Buttons) dynamically from DB in Page Load.
    In every postback these controls are recreated which isn't needed for me.
    So I put my controls creating code in "If Page.IsPostBack = False Then"
    Now controls isn't created after I press button and postback is called, but now I lose event of that button and nothing happens.

    I'm creating dynamic registration from and after button is clicked it should not recreate controls again, but write "Saved" etc.

    How to fire event before button handler is lost?

  2. #2
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    You are going to have to add the controls to the control tree on each load of the page, so instantiate and add your controls in the page init event handler.

  3. #3
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    Well, the issue is really that the page needs to create those controls first. After that has been done and viewstate reloaded, it goes about handling any events that were raised.

    It has to do this, otherwise you will never get the control to handle its own event if it hasn't been created.

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2000
    Location
    Europe, Lithuania
    Posts
    309
    I don't understood. Can you explain more dataily?

  5. #5
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    If you create controls in runtime, you will always have to create them on each load of the page. ViewState will always preserve their values (by default).

  6. #6
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    Yes, what we all said is correct (I elected not to go into the gory details), and MS recommends doing this in the Page Init event handler, rather than the page load.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width