开发者

ASP.NET - What is the easiest generic way to save form data and retrieve it when the user navigates back to the page?

开发者 https://www.devze.com 2023-02-11 23:31 出处:网络
What is the easiest way to save form data and retrieve it when the user navigates back to the page? We have an application process that consists of several web forms. If the user clicks to go back a

What is the easiest way to save form data and retrieve it when the user navigates back to the page?

We have an application process that consists of several web forms. If the user clicks to go back a step we would like to auto-populate the fields. I am assuming there is a common generic way to do this without having to mess with individual c开发者_运维百科ontrols - what is it?


Put all your forms on the same page and enable ViewState.

That is, instead of using three distinct pages, use a single page that has panels for each of the virtual "pages." Just keep track of which page the user is on (with another ViewState-managed property), and show/hide the forms as appropriate to that page.

The next/back controls should just post to itself and increment/decrement the current page.

Since it's all the same form, and it's always posting to itself, ViewState will persist the field values automatically.

The only thing that won't work is if they click their browser's "back" button. Just block it using window.onbeforeunload to prevent it.


Easiest way would be to store it in the View State, which could exist on the server or could exist in a relational database.


Bind the value of the controls to a stateful model.


You could also use sessions which will be given a value on the last page and then checked if exists and retrieved on the previous page.

0

精彩评论

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