views:

122

answers:

4

Hi all, Pls somebody help me with viewsate. Suppose i have created two forms. First form contains First name and Last name and one button called NEXT. And Second form contain two fields and two button like Back and Save. While i am entering some value in form1 pressing one NEXT button and redirecting to second page. There when i am pressing Back button from second page it should come to first page whichever data i filled should exists, but in my case its not showing only empty form i can see when i am pressing on back button.

For this i have used viewstate mechanism. in page directory i have set enableviewstate=true. postbackurl in both the button. Pls somebody help me what is wrong with me.

Thanks, Sumit

A: 

You can call a javascript function that is doing a "real" back. Maybe I am missing something but this is what I would do.

onClick="history.go(-1)"
Sebastien Lachance
+1  A: 

ViewState will help you ship data between views/postbacks of the same page, but isn't really going to help you when moving data between separate pages.

In your first page, populate a cookie or database with your form fields. Any form can then update the cookie, delete it, or what have you.

David Lively
+2  A: 

Viewstate won't carry information from one WebForm to another. It only carries information across postbacks on the same WebForm.

You want to use another method, like SessionState, to carry information from the first page to the second page. Otherwise, you could combine all your inputs on the same page and separate them into multiple steps using something like the ASP.NET Wizard control.

David Lively's suggestions of cookie or database solutions are good, too.

Cam Soper
I think u didn't understand my problem. I don't want to pass any information from one page another page. Just i wanted, suppose i have filled my data in first page then by pressing next button went to second page. In second there is button like Back. If i press it it should go to first page and whichever data i had filled should be there in first page itself. Hope i explained my problem.
Sumit
Ah, okay, I get it now. You're right - I didn't understand your question.The same principle applies, though. When you go back to page 1, the page is reloading with a fresh viewstate, with no information in it. You'll need to populate the data you want displayed in the fields, which means you'll need to store it somewhere (cookie, session state) before you leave page 1 for page 2 the first time.
Cam Soper
Also, you really should look at the wizard control, as it would enable you to put all your steps on the same page, and therefore the same viewstate.
Cam Soper
A: 

When a page is called from some other page it is not a post back, it is viewed as if it is a first time call... When a page is called from the same page then it is termed as a post back... View state or in the sense control values are maintained only during post back, and gets reseted to form values during first time call...

This is the reason behind why you are not seeing the values of the controls.

As others suggested, try using session or cookies and the best option would be Wizard.

The King