0

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

2
  • why don't you use standard asp.net wizard control? Commented Nov 5, 2009 at 16:47
  • as per the viewsate concerned in asp.net, if we enter some data in form if some error occurred server side and if we come back to the page again still we can see the data,its not lost, thats what viewstate says. but in my case why not able to do this??? I go back page like this: in Back button PostbackUrl="Default.aspx". Commented Nov 5, 2009 at 16:54

4 Answers 4

2

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.

Sign up to request clarification or add additional context in comments.

3 Comments

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.
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.
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.
1

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.

Comments

0

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

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.