Viewstate and dynamicly added controls

  • Thread starter Anders K. Jacobsen [DK]
  • Start date
A

Anders K. Jacobsen [DK]

Hi im creating a (or is starting but need your advise) search page for some
products which has surdden charataristicas which all should be serachable.
These charataristicas can be added runtime so to say and the charataristicas
is stored in the database where they are decribed eg. The charataristicas is
a Textbox, width=20 and so on.

Therefore I need to dynamically add controls to my search page according to
the database. But how will viewstate "handle" this. I guess i have to
rebuild the page structure on every postback, correct?

But will this rebuild destroy the state of the controls that i added on last
postback? If yes, what do I do then? Is it "impossible".

I really appriciate your help and thougts on this. Thanks!

Anders
 
K

Karl Seguin

Anders:
It's all about timing. If you re-recreate the controls (and yes, you are
correct, you must rebuild on postback) before the LoadViewState event. In
other words, if you rebuild your control's in the Page's Init event, the
state will be maintained.

You should really check out (free)
http://www.denisbauer.com/ASPNETControls/DynamicControlsPlaceholder.aspx
which automatically rebuilds the controls for you. It sounds like you might
have quite a few, and this might be the easiest way to manage them.

karl
--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
 

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

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top