Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Professional For advanced ASP.NET 1.x coders. Beginning-level questions will be redirected to other forums. NOT for "classic" ASP 3 or the newer ASP.NET 2.0 and 3.5
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 20th, 2003, 02:57 PM
Registered User
 
Join Date: Sep 2003
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Persisting viewstate between pages

I am trying to persist a page's viewstate when I redirect to another page, so that I can restore it upon returning to the original page. I have overridden the SavePageStateToPersistenceMedium and LoadPageStateFromPersistenceMedium methods, but the Load method doesn't get called when returning to the original page, so the changes are lost.

WHAT GIVES?!


 
Old September 22nd, 2003, 10:25 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

You are seeing behavior that is correct by design. Viewstate only reloads when you do a postback. Otherwise the page is created fresh every time you access it from a link/redirect to it. The point of viewstate is not to maintain the state of a page between views of that page, just while that page is being viewed each time. It's designed to maintain the state of the controls on the page.

What you are describing is more an application of session state. Look into using that to save off values of controls you'd like to restore.

An alternative to this if you really want to have several "pages" and maintain each one's viewstate is to create one ASPX that has several user controls. You can turn the user control on and off (property Visible=True|False) depending on what "page" you want to see and because all the controls are on the same page, and all the controls are in the user controls all the viewstate information for everything is maintained.

Peter
 
Old September 22nd, 2003, 11:12 AM
Registered User
 
Join Date: Sep 2003
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yeah, I'm currently doing that, but now I've run into an issue where I need to switch between different forms because I'm using an IFRAME in my main window. I need to be able to display a login form from the main window, no matter which form is currently displayed in the IFRAME. Therefore, within the IFRAME I need to switch from the current form to the login form, yet maintain the viewstate so I can go back. I don't want to have to embed the login form on every page that can be displayed in the IFRAME.


 
Old September 22nd, 2003, 11:30 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Well... one idea would be to force login before you start generating a form state that you need to persist. Otherwise, you'll need to save all the form state data separately (session, or other persistant-across-pages method).

I don't know if it's possible to take the viewstate object for a page, drop it in the session, then manually restore it when you return to the page. I don't see a reason that wouldn't work, it's just a bit of tricky coding. Seeing as you can override the page's LoadPageStateFromPersistenceMedium method or the other viewstate related methods, there is probably some way of doing it manually. When some event happens that causes the page to redirect to the login page, you save the viewstate object into the session. Then when you return to the page (that is, the page load's without a postback) the page can check the session to see if there is a viewstate object for it and load it up. I have worked with the viewstate persistance methods with some success when writing custom server controls so I know it's doable. Just not sure about saving the WHOLE viewstate. (If you do manage to figure it out, I'd recommend that you make sure you remove the viewstate object from session when you retrieve so as not to confuse a hit to the page when you aren't really returning.)

Peter





Similar Threads
Thread Thread Starter Forum Replies Last Post
Persisting Simple Association aadz5 Hibernate 1 August 13th, 2008 03:49 AM
Variables persisting in memory Keith Smith Access VBA 2 February 12th, 2008 08:34 AM
persisting data in a web app badgolfer ASP.NET 1.0 and 1.1 Basics 3 October 20th, 2004 01:59 PM
No viewstate datagrid failure on "more pages" planoie ASP.NET 1.0 and 1.1 Professional 4 May 28th, 2004 01:54 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.