Click here to Skip to main content
15,898,035 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Guys

I have 2 pages. Page_1 and Page_2.

In Page_1 I EneableViewstate="true" on top of the page.
Also Page_1 has a link that redirects to Page_2.

the code for Page_Load() of Page_1 is below.

C#
if (!Page.IsPostBack)
            {
               loadgrdAvailableStaffOnPageLoad();
               loadgrvViewAppointmentsOnPageLoad();
            }
            else if (Page.IsPostBack)
            {
                loadgrdAvailableStaffOnPageLoadViewState();
                loadgrvViewAppointmentsOnPageLoadViewState();
            }


In Page_2 I have button "cancel" with this code below
C#
Response.Redirect("Page_1.aspx");// So it goes to Page_1

Now correct me if am wrong because am confuse.

On initial Page_Load() am expecting the application to go inside this "if" statement below:

C#
if (!Page.IsPostBack)
            {
               loadgrdAvailableStaffOnPageLoad();
               loadgrvViewAppointmentsOnPageLoad();
            }
Then after coming back from Page_2, the application should be loading

this part:
C#
else if (Page.IsPostBack)
            {
                loadgrdAvailableStaffOnPageLoadViewState();
                loadgrvViewAppointmentsOnPageLoadViewState();
            }


What can I do to restore Page_1 information after coming back from Page_2??
Posted
Updated 21-Sep-11 23:11pm
v2

1 solution

ViewState is only available if you stay on the same page. If you're navigating between pages, you'll need to look at other methods of persisting the information:

1. Session State: http://msdn.microsoft.com/en-us/library/ms178581.aspx[^]

2. QueryString: Passing variables between pages using QueryString[^]

If the information is in any way more complex than just a couple of primitive values (integer, string etc) I'd use Session State. It'll let you persist complex objects across requests for different pages.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900