Dynamically adding controls

  • Thread starter Thread starter Chris Botha
  • Start date Start date
C

Chris Botha

I am adding controls dynamically to the page as per the samples there are on
the Web and it works - I can create text boxes, buttons, my own user
controls, whatever, on the fly and initialize them and add them to a
placeholder no problem.
However when I post back and the page displays again then all of the
controls are gone. I create them when the IsPostBack is false, because the
idea is to validate on post back, and if the data is invalid then the
controls should keep whatever the user entered and the user can correct it.

My question - how can I create for example one text box (when IsPostBack is
false), add it to the placeholder and after the user posted, the text box
will still be on the page and will contain the text the user entered (=
should behave as if the text box was added by the designer).

Thanks.
 
Got this to work. Don't test for IsPostBack in the Page_Load, just create
them and add them to the place holder every time - they keep the values as
entered by the user. Strange, I thought, then maybe not ...

Still, I have to access the database with every post back now to read the
control info to be created, so if someone knows how to do this once only
when the page loads the 1st time, I would like to know too.
 
Cache the data perhaps.
Chris Botha said:
Got this to work. Don't test for IsPostBack in the Page_Load, just create
them and add them to the place holder every time - they keep the values as
entered by the user. Strange, I thought, then maybe not ...

Still, I have to access the database with every post back now to read the
control info to be created, so if someone knows how to do this once only
when the page loads the 1st time, I would like to know too.
 
Back
Top