开发者

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 which开发者_运维知识库ever 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜