473,705 Members | 5,438 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Saving/restoring viewstate between different pages..

RCS
I have an app that I have different "sections" that I want to switch back
and forth from, all while having the server maintain viewstate for each
page. In other words, when I am on Page1.aspx and set textboxes, radio
buttons, etc - that viewstate is fine. Then I have a linkbutton that does a
Server.Transfer over to Page2.aspx. When I Server.Transfer back to
Page1.aspx, the viewstate info is lost.

I ran across another example of this last weekend too - imagine filling out
a registration and order form, type pages.. and once you click "Review"
(which sends you to a different page) - if you want to go back to the last
page to change your information, the viewstate is lost.

ANYhow, so what I've done is on the linkbutton that lets you leave the page,
I put:

Session.Add("Qu estionnaireView state",this.Vie wState);

Server.Transfer ("Default.aspx" ,true);

Then, when you come back to this page, I put this in page_load:

StateBag objSB = ((StateBag)Sess ion["QuestionnaireV iewstate"]);

if ( objSB != null )

{

Response.Write( objSB.Count + " is number of items<br>");

foreach (string val in objSB.Keys)

{

Response.Write( "Setting '" + val + "' to '" + objSB[val].ToString() +
"'<br>");

this.ViewState[val] = objSB[val].ToString();

}

}

else

{

Response.Write( "StateBag is null");

}

Turns out that this.ViewState has 0 items before it leaves - otherwise, this
seems like it might work. Any ideas on how to preserve viewstate between
pages and allowing the user to click back and forth between pages - all
while keeping thier viewstate data alive?? Thanks


Nov 19 '05 #1
3 4570
I think your understanding of ViewState is confused.

What is the purpose of you preserving content between pages? You're using
the Session, which is really not intended for temporary storage of page
data. And even if you do want it in the Session, why would you preserve it
in the ViewState on top of that?

What you may want to do instead is have all your functionality on one page,
inside sections you can set/reset the Visibility on. That way, you don't
have to play around with manually handling the Session and/or ViewState at
all. It will all be handled automatically for you.

"RCS" <rs****@gmail.c om> wrote in message
news:hu******** ******@newssvr3 3.news.prodigy. com...
I have an app that I have different "sections" that I want to switch back
and forth from, all while having the server maintain viewstate for each
page. In other words, when I am on Page1.aspx and set textboxes, radio
buttons, etc - that viewstate is fine. Then I have a linkbutton that does a
Server.Transfe r over to Page2.aspx. When I Server.Transfer back to
Page1.aspx, the viewstate info is lost.

I ran across another example of this last weekend too - imagine filling
out a registration and order form, type pages.. and once you click
"Review" (which sends you to a different page) - if you want to go back to
the last page to change your information, the viewstate is lost.

ANYhow, so what I've done is on the linkbutton that lets you leave the
page, I put:

Session.Add("Qu estionnaireView state",this.Vie wState);

Server.Transfer ("Default.aspx" ,true);

Then, when you come back to this page, I put this in page_load:

StateBag objSB = ((StateBag)Sess ion["QuestionnaireV iewstate"]);

if ( objSB != null )

{

Response.Write( objSB.Count + " is number of items<br>");

foreach (string val in objSB.Keys)

{

Response.Write( "Setting '" + val + "' to '" + objSB[val].ToString() +
"'<br>");

this.ViewState[val] = objSB[val].ToString();

}

}

else

{

Response.Write( "StateBag is null");

}

Turns out that this.ViewState has 0 items before it leaves - otherwise,
this seems like it might work. Any ideas on how to preserve viewstate
between pages and allowing the user to click back and forth between
pages - all while keeping thier viewstate data alive?? Thanks

Nov 19 '05 #2
RCS
Normally, I'd completely agree with you. With that said, that IS what *EACH*
page does. EACH page has several visible/invisible panels (that make up
virtual pages, or tabs) that have all sorts of information - that results in
a several dozen (if not hundreds of) controls on each page. I want to break
up the functionality further into logical chunks, because to do this all on
one page is just WAY too much.

I ended up spending the whole day on this and ran into brick wall after
brick wall. I am in the process of just writing my own little handler for
basically copy the pertinent properties (like .Text, .SelectedIndex, etc)
into a hash table (stored by control ID and property), then store that hash
table in a session variable.

It REALLY seems to me, and REALLY frustrates me that I have to do this. It
just really seems that since "something" keeps the viewstate information for
a page, I should be able to cache that in a session variable, then re-apply
it later if I come back to that page. Instead, I have to hack something
together??

Anyone else have any other ideas on a more elegant way to do this?
Difficulty: I've messed around with serializing the form, saving the form
off to a session variable and overrriding Save/Load viewstate from medium
methods. The closest I got, was copying the instantiated form off to a
session variable, then re-applying it when you come back to the page. The
*first* load works fine, but if you re-submit the page, it loses all it's
viewstate info (I assume because OnInit built it's viewstate info off of
what IT did)..
Grrr....... :-(
"Random" <ci*******@hotm ail.com> wrote in message
news:O3******** ******@TK2MSFTN GP10.phx.gbl...
I think your understanding of ViewState is confused.

What is the purpose of you preserving content between pages? You're using
the Session, which is really not intended for temporary storage of page
data. And even if you do want it in the Session, why would you preserve
it in the ViewState on top of that?

What you may want to do instead is have all your functionality on one
page, inside sections you can set/reset the Visibility on. That way, you
don't have to play around with manually handling the Session and/or
ViewState at all. It will all be handled automatically for you.

"RCS" <rs****@gmail.c om> wrote in message
news:hu******** ******@newssvr3 3.news.prodigy. com...
I have an app that I have different "sections" that I want to switch back
and forth from, all while having the server maintain viewstate for each
page. In other words, when I am on Page1.aspx and set textboxes, radio
buttons, etc - that viewstate is fine. Then I have a linkbutton that does
a Server.Transfer over to Page2.aspx. When I Server.Transfer back to
Page1.aspx, the viewstate info is lost.

I ran across another example of this last weekend too - imagine filling
out a registration and order form, type pages.. and once you click
"Review" (which sends you to a different page) - if you want to go back
to the last page to change your information, the viewstate is lost.

ANYhow, so what I've done is on the linkbutton that lets you leave the
page, I put:

Session.Add("Qu estionnaireView state",this.Vie wState);

Server.Transfer ("Default.aspx" ,true);

Then, when you come back to this page, I put this in page_load:

StateBag objSB = ((StateBag)Sess ion["QuestionnaireV iewstate"]);

if ( objSB != null )

{

Response.Write( objSB.Count + " is number of items<br>");

foreach (string val in objSB.Keys)

{

Response.Write( "Setting '" + val + "' to '" + objSB[val].ToString() +
"'<br>");

this.ViewState[val] = objSB[val].ToString();

}

}

else

{

Response.Write( "StateBag is null");

}

Turns out that this.ViewState has 0 items before it leaves - otherwise,
this seems like it might work. Any ideas on how to preserve viewstate
between pages and allowing the user to click back and forth between
pages - all while keeping thier viewstate data alive?? Thanks


Nov 19 '05 #3
RCS
Just as a followup for anyone else who is looking for an answer to this, it
seems what I was attempting to do, wasn't possible.

However, it dawned on me there is another - and dare I say better way to do
this. I took all of my major chunks of functionality, and put them into User
Controls on ONE page. Then, I have my section navigation just set the
..Visible = true; or false to whichever controls (which contain chunks of
functionality) I need. Best of all, It keeps viewstate for all the controls
(visible or not) within all of the User Controls. So I can easily switch
between which user control is visible!

Anyhow, this was a pretty specific situation that I needed and this worked
out quite well. For whatever it's worth....
"RCS" <rs****@gmail.c om> wrote in message
news:tS******** *******@newssvr 17.news.prodigy .com...
Normally, I'd completely agree with you. With that said, that IS what
*EACH* page does. EACH page has several visible/invisible panels (that
make up virtual pages, or tabs) that have all sorts of information - that
results in a several dozen (if not hundreds of) controls on each page. I
want to break up the functionality further into logical chunks, because to
do this all on one page is just WAY too much.

I ended up spending the whole day on this and ran into brick wall after
brick wall. I am in the process of just writing my own little handler for
basically copy the pertinent properties (like .Text, .SelectedIndex, etc)
into a hash table (stored by control ID and property), then store that
hash table in a session variable.

It REALLY seems to me, and REALLY frustrates me that I have to do this. It
just really seems that since "something" keeps the viewstate information
for a page, I should be able to cache that in a session variable, then
re-apply it later if I come back to that page. Instead, I have to hack
something together??

Anyone else have any other ideas on a more elegant way to do this?
Difficulty: I've messed around with serializing the form, saving the form
off to a session variable and overrriding Save/Load viewstate from medium
methods. The closest I got, was copying the instantiated form off to a
session variable, then re-applying it when you come back to the page. The
*first* load works fine, but if you re-submit the page, it loses all it's
viewstate info (I assume because OnInit built it's viewstate info off of
what IT did)..
Grrr....... :-(
"Random" <ci*******@hotm ail.com> wrote in message
news:O3******** ******@TK2MSFTN GP10.phx.gbl...
I think your understanding of ViewState is confused.

What is the purpose of you preserving content between pages? You're
using the Session, which is really not intended for temporary storage of
page data. And even if you do want it in the Session, why would you
preserve it in the ViewState on top of that?

What you may want to do instead is have all your functionality on one
page, inside sections you can set/reset the Visibility on. That way, you
don't have to play around with manually handling the Session and/or
ViewState at all. It will all be handled automatically for you.

"RCS" <rs****@gmail.c om> wrote in message
news:hu******** ******@newssvr3 3.news.prodigy. com...
I have an app that I have different "sections" that I want to switch back
and forth from, all while having the server maintain viewstate for each
page. In other words, when I am on Page1.aspx and set textboxes, radio
buttons, etc - that viewstate is fine. Then I have a linkbutton that does
a Server.Transfer over to Page2.aspx. When I Server.Transfer back to
Page1.aspx , the viewstate info is lost.

I ran across another example of this last weekend too - imagine filling
out a registration and order form, type pages.. and once you click
"Review" (which sends you to a different page) - if you want to go back
to the last page to change your information, the viewstate is lost.

ANYhow, so what I've done is on the linkbutton that lets you leave the
page, I put:

Session.Add("Qu estionnaireView state",this.Vie wState);

Server.Transfer ("Default.aspx" ,true);

Then, when you come back to this page, I put this in page_load:

StateBag objSB = ((StateBag)Sess ion["QuestionnaireV iewstate"]);

if ( objSB != null )

{

Response.Write( objSB.Count + " is number of items<br>");

foreach (string val in objSB.Keys)

{

Response.Write( "Setting '" + val + "' to '" + objSB[val].ToString() +
"'<br>");

this.ViewState[val] = objSB[val].ToString();

}

}

else

{

Response.Write( "StateBag is null");

}

Turns out that this.ViewState has 0 items before it leaves - otherwise,
this seems like it might work. Any ideas on how to preserve viewstate
between pages and allowing the user to click back and forth between
pages - all while keeping thier viewstate data alive?? Thanks



Nov 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
5452
by: Jacob H | last post by:
Hello list... I'm developing an adventure game in Python (which of course is lots of fun). One of the features is the ability to save games and restore the saves later. I'm using the pickle module to implement this. Capturing current program state and neatly replacing it later is proving to be trickier than I first imagined, so I'm here to ask for a little direction from wiser minds than mine! When my program initializes, each game...
5
7254
by: Michael Albanese | last post by:
Can you save objects a (custom class) to Viewstate and then get them on a later page?? I have a custom class for an ASP.Net application that I would like to make available across several web pages. For example: page1.aspx accepts a users's name, age and gender, instantiated the new class and redirects to page2.aspx
4
4043
by: Ersin Gençtürk | last post by:
Server : WEB System.Web.HttpUnhandledException: Exception of type System.Web.HttpUnhandledException was thrown. ---> System.Web.HttpException: The View State is invalid for this page and might be corrupted. at System.Web.UI.Page.LoadPageStateFromPersistenceMedium() at System.Web.UI.Page.LoadPageViewState() at System.Web.UI.Page.ProcessRequestMain() --- End of inner exception stack trace --- at System.Web.UI.Page.HandleError(Exception e)...
2
2602
by: Mike | last post by:
hi to all does any body know or receive this message before and how i can repare this: The viewstate is invalid for this page and might be corrupted. thank's Mike
3
1551
by: Denis Georgievski | last post by:
I am optimizing my web application written in ASP/VB.NET 1.1. I have number of pages that have dropdown list server controls that contain large number of items. Before redesigning the data access I would like to try by saving the view state to the server if this can speed up the access to these heavy pages. Could somebody give me a working example on saving the viewstate to the server written in VB. Thanks
4
1609
by: McGeeky | last post by:
I am implementing a series of sequential web pages, a wizard, whereby the user can step back to a previous page. I want to restore the state of those pages if the user navigates back to them. Only being new to ASP.Net, I am not sure if it provides facilities to manage this scenario. Any info would be appreciated, thanks. -- McGeeky http://mcgeeky.blogspot.com
15
3741
by: Marcus Kwok | last post by:
How do you save the formatting options for a stream? In the program below, notice that when I define my operator<<() for the custom type, it permanently changes the output format of the stream: #include <iostream> #include <iomanip> struct Data { double d; };
6
6256
by: scottrm | last post by:
Hi Users seem to be getting the following intermitent error whe they post a form. Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that <machineKeyconfiguration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster.
4
2287
by: =?Utf-8?B?TUNN?= | last post by:
I am trying to disable ViewState at the application level. I have the following line in my web.config: <pages enableViewState="false"></pages> But it is not working. What can I do?
0
8690
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9139
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9034
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7895
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5933
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4440
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4704
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2491
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2083
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.