Dynamically adding controls

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.
 
C

Chris Botha

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.
 
S

Showjumper

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top