ViewState, Dynamic UserControls, and the Back Button

  • Thread starter Thread starter John Hamm
  • Start date Start date
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?
 
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
 
Back
Top