开发者

Go back previous page (keep viewstate) with ASP.NET UpdatePanel control

ASP.NET 4.0 Webform website

master page: left side panel (navigation menu purpose): use UpdatePanel control (AJAX), so when selecting new menu, the whole page won't reload. Only conte开发者_如何学Cnt part will be updated.

My question is -- I want to be able to use browser back button to go back to previous menu (with form state saved). However, when looking into the viewstate, it's always the same. Is there any way to do this? Thanks.


I guess one work around would be, when a user selects a menu item from the menu, put that selection in a session variable and in the page load. Then when the user hits the browser back button, you can set the menu in the page load, since you have values in your session variable.


What pst is referring to is "cross-page posting".

On your source page, you will need to set the asp button's postbackurl to your target page url.

In the target page c# onload method, set page.previouspage to your source page. Check if the previouspage's post was a crosspagepost.

If true, get zource page's viewstate.

How do you get access to the source page's viewstate from the target page? Save the source page's viewstate in the source page before going to the target page. Save the viewstate in an asp hidden variable on the source page, then get it in the target page using previouspage.findcontrol("variable name").

After getting the source page's viewstate, save it in an asp hidden variable on the target page.

When you want to return to the source page, you will do everything above in reverse, in a way.

The "back to previous page" link button will use the source page url for the postbackurl value.

In the source page's onload c# method, set the page.previouspage url to the target page's url. Check if the previouspage's post was a cross-page post.

If true, in the source page (after returning from target page) use previouspage.findcontrol("savedSourcePageViewstate") to get the saved viewstate of the source page.

I am not exactly sure yet how to then change the source page's viewstate to the saved viewstate. you might actually have to do it in the target page's backttopreviouspage button's click handler.

I am working at developing this process right now in a project i'm developing at work.

When i get it working, i'll create a full walkthrough for this, with code examples, and post the link to the walkthrough here.

However, i already haveworking the cross-page posting process of getting data from the source page in the target page.

It is secure, and is the best method that i have come across for getting data from one page to anotherin an asp.net webforms application.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜