PDA

Click to See Complete Forum and Search --> : Dynamically-created-controls Event firing problem


Norkis
Jun 1st, 2004, 03:38 AM
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?

Lethal
Jun 1st, 2004, 11:43 AM
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.

nemaroller
Jun 1st, 2004, 11:46 AM
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.

Norkis
Jun 1st, 2004, 11:47 AM
I don't understood. Can you explain more dataily?

Serge
Jun 1st, 2004, 01:26 PM
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).

Lethal
Jun 1st, 2004, 01:54 PM
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.