sync viewstate when controls are removed

D

Don

I need some suggests on how to manage the viewState on my page.

I have multiple checkBoxLists that are dynamically created and need
then synced up with the viewstate. My problem is that on each postback
I may have less items than the viewstate has because some are not
created. When the viewState is loaded it seems to load the controls in
the order they were created so if the first control is now gone it's
data is assigned to what was the second control.

I'll give an example:I have a parent checkBoxList that shows States in
the United States. For each State that is checked I get another
checkBoxList with the cities in that state.
Suppose the user clicks Iowa. I postback occurs and I dynamically
create another checklist box for the cities in Iowa and populate it
from the database.
Now the user clicks Ohio, a postback occurs and I loop thorugh the
selected states and create controls from each of them. The viewStates
handles loading the data back for Iowa (and preserves data and checked
boxes) and I load Ohio from the database.
All of this works find and postbacks do not cause a problem.

Now, assume the user removes the check by Iowa so I now longer want to
display the cities in Iowa. During the postback I loop through the
selected states and find only Ohio. I then create one checkBoxList for
Ohio but when the page loads I notice the Ohio checkBoxList has the
cities for Iowa.

This is because the viewState loads controls in the order they were
first put on the page.
How can I get the applciation to skip those that are not created? It
would be best if the viewState used the id rather that the order items
were added.
How can I access the items on the viewState? If I can get the parent
Control from the viewState I can tell what was checked the last time
and create these controls, then I'll remove the ones that need to be
removed.
Can anyone offer any suggests?

I've tried overwriting loadViewState and saveViewState but I always get
this result.

Thanks,
Don
 

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,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top