ViewState, Dynamic UserControls, and the Back Button

Discussion in 'ASP .Net' started by John Hamm, Nov 7, 2003.

  1. John Hamm

    John Hamm Guest

    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?
    John Hamm, Nov 7, 2003
    #1
    1. Advertising

  2. John Hamm

    Jeff Guest

    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

    "John Hamm" <> wrote in message
    news:...
    > 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?
    Jeff, Nov 8, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page