ViewState, Dynamic UserControls, and the Back Button

J

John Hamm

My web application dynamically creates a UserControl and saves it to a
Session variable called LastControl. When a postback occurs, I simply
load the LastControl and everything works great.

The problem occurs when the user hits the Back button. Then the
"LastControl" might be a different User Control and so when I reload
it, it causes instance errors since the user control it is expecting
is no longer in a Session variable.

Some solutions I have thought about are:

1. Creating a Session variable for each User Control and keeping it in
memory. I am afraid, though, that this could tax the web server's
memory, and this just seems like a kludgy solution.

2. Figure out a way to save the User Control and put it in the page's
ViewState. This would be ideal because then I would simply load the
dynamic control from the current page's view state and there would
never be an issue with the back button and no memory would be taken up
on the server.


Has anyone had success storing a User Control in a page's view state?
 
J

Jeff

My preferred solution would be to create the contorl every time you need it.

If that is too expensive, is the control different for each user? If not,
maybe you can use the Cache object instead of session. This way, you only
keep one copy and can better afford to keep older data around.

Jeff
 

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,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top