Deleting controls & their data from ViewState

B

Bjorn Sagbakken

With ASP.NET 2.0:

I have managed to create controls dynamically in an asp:table, populating
them with database info, and even adding empty rows of controls for adding
new data to the database. For all this to work I add a ViewState counter, so
far so well.

But I also want to clear the form, remove the controls and remove all
ViewState data. This is done with some code behind a button. I have tried
various kind of commands, and they all work - but I have to hit the
clear-button twice.

My guess goes for timing in the page events. The controls are loaded
dynamically in the page-load event, and I guess the clear-viewstate call
behind my clear-button is executed after this event. This is why I have to
hit the clear-button twice. But how can I make this happen in one single
postback? Any ideas?

Bjorn
 
B

Bjorn Sagbakken

Bjorn Sagbakken said:
With ASP.NET 2.0:

I have managed to create controls dynamically in an asp:table, populating
them with database info, and even adding empty rows of controls for adding
new data to the database. For all this to work I add a ViewState counter,
so far so well.

But I also want to clear the form, remove the controls and remove all
ViewState data. This is done with some code behind a button. I have tried
various kind of commands, and they all work - but I have to hit the
clear-button twice.

My guess goes for timing in the page events. The controls are loaded
dynamically in the page-load event, and I guess the clear-viewstate call
behind my clear-button is executed after this event. This is why I have to
hit the clear-button twice. But how can I make this happen in one single
postback? Any ideas?

I guess not...ideas I mean.
So is my state of mind to, except I start to believe I need to perform a
double roundtrip to achieve this.
But how do I force a postback from server-code? (...yes I know bad
programming here will start an endless loop...)

Bjorn
 

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,774
Messages
2,569,598
Members
45,160
Latest member
CollinStri
Top