Save and load PageViewState

Last post 11-16-2009 5:17 AM by lojkine. 4 replies.

Sort Posts:

  • Save and load PageViewState

    11-12-2009, 11:35 AM
    • Member
      6 point Member
    • lojkine
    • Member since 06-19-2009, 12:22 PM
    • Posts 6

    Hello!

    Is it possible to save an entire PageViewState and load it later? My idea was to associate the PageViewState to the user currently logged and when the user returned to the page, it would be like the last time he/she had visited it.

    Thanks for your answers

    Regards

    Frank 

  • Re: Save and load PageViewState

    11-12-2009, 2:18 PM
    Answer
    • All-Star
      25,468 point All-Star
    • budugu
    • Member since 01-12-2006, 7:15 PM
    • North Carolina
    • Posts 3,789
    Vijay Kodali || My Blog


    "Don't be afraid to be wrong; otherwise you'll never be right."
  • Re: Save and load PageViewState

    11-12-2009, 4:39 PM
    • Participant
      790 point Participant
    • dotnetkode
    • Member since 01-22-2008, 9:47 PM
    • Herndon, VA
    • Posts 132

    Can you give a bit of context to the task you are trying to acheive?

    ViewState automatically goes back and forth between postbacks.

    ~ Remember To Mark The Posts Which Helped You As The ANSWER ~
  • Re: Save and load PageViewState

    11-12-2009, 10:43 PM
    • Contributor
      5,228 point Contributor
    • RickNZ
    • Member since 01-01-2009, 8:43 AM
    • Nelson, New Zealand
    • Posts 873

    lojkine:

    Is it possible to save an entire PageViewState and load it later? My idea was to associate the PageViewState to the user currently logged and when the user returned to the page, it would be like the last time he/she had visited it.

    Sure.  Just override SavePageStateToPersistenceMedium() and LoadPageStateFromPersistenceMedium() in your Page.

    I give examples of how to do this in my book.


  • Re: Save and load PageViewState

    11-16-2009, 5:17 AM
    • Member
      6 point Member
    • lojkine
    • Member since 06-19-2009, 12:22 PM
    • Posts 6

    Hello!

    Thanks for all your answers. @Vijay your answer was particularly useful because Esposito's was what I was looking for. After tweaking a beat with the override of the two methods I came to the conclusion that, yes, I can load a previously saved state for a page from another session BUT there's a couple of strange things happening:

    1) First method firing is SavePageStateToPersistenceMedium -> I managed to get this one by coding if (!Page.IsPostBack) LoadPageStateFromPersistenceMedium.

    2) Despite my previous code, the viewstate is only loaded after I postback the page to server (meaning that, hadn't I prevent the Save I would never get the saved state).

    Dino Esposito's article lead me to this one in CodeProject: http://www.codeproject.com/KB/applications/persistentstatepage.aspx which, I think, is what I need but somehow it's not working at all, got to make further investigation.

    Anyway, thanks again for all your answers.

    Regards

    Frank 

Page 1 of 1 (5 items)