简体   繁体   中英

Need help in asp.net viewstate

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

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.

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.

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)"

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 technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM