R
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("QuestionnaireViewstate",this.ViewState);
Server.Transfer("Default.aspx",true);
Then, when you come back to this page, I put this in page_load:
StateBag objSB = ((StateBag)Session["QuestionnaireViewstate"]);
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
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("QuestionnaireViewstate",this.ViewState);
Server.Transfer("Default.aspx",true);
Then, when you come back to this page, I put this in page_load:
StateBag objSB = ((StateBag)Session["QuestionnaireViewstate"]);
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