Dynamic controls

M

Mike

Hi,

I am building a web form with dynamic controls. Some need to be visible and some not. When clicking on a button, all controls become visible. I have used code behind to do that, but when I set the value of a control (ie. label) and then click the button to show all controls, these value are lost. Should I use ViewState and save the state of each single control? Or is that a better method? Any resouce or sample would be highly appreciated.

Thanks
Mike
 
G

Guest

The ViewState should intrinsically hold the set values, unless somewhere in the process (Page_Load, etc.) they are getting re-loaded with blank text.
 
K

Ken Cox [Microsoft MVP]

You might want to check out Denis Bauer's free DynamicControlsPlaceholder
control that seems to do what you need:

It "behaves like a placeholder but additionally handles recreating dynamic
controls on subsequent requests."

http://www.denisbauer.com/ASPNETControls/DynamicControlsPlaceholder.aspx


Hi,

I am building a web form with dynamic controls. Some need to be visible and
some not. When clicking on a button, all controls become visible. I have
used code behind to do that, but when I set the value of a control (ie.
label) and then click the button to show all controls, these value are lost.
Should I use ViewState and save the state of each single control? Or is that
a better method? Any resouce or sample would be highly appreciated.

Thanks
Mike
 
S

Saravana [MVP]

Check out this article to know how to maintain viewstate in dynamically created controls,
http://www.codeproject.com/aspnet/retainingstate.asp

--
Saravana
Microsoft MVP - ASP.NET
www.extremeexperts.com




Hi,

I am building a web form with dynamic controls. Some need to be visible and some not. When clicking on a button, all controls become visible. I have used code behind to do that, but when I set the value of a control (ie. label) and then click the button to show all controls, these value are lost. Should I use ViewState and save the state of each single control? Or is that a better method? Any resouce or sample would be highly appreciated.

Thanks
Mike
 
G

Guest

Mike
You have to be careful when setting the value, because the button click event happens after the pageload event and as David says the value might be set to blank on page load.
 

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

Top