在非回发、非跨页面回发场景下,如何保存和恢复会话页面视图状态?
目前,我通过重新查询数据库来填充网格来恢复状态,但页面加载速度太慢。相反,我想将视图状态保存在会话变量中,并在用户重新访问页面时恢复它。这是怎么做到的?我应该使用 SessionPageStatePersister 吗?这不是回发情况,甚至不是跨页面回发。
背景:我使用了带有母版页和多个选项卡式内容页的 VS 2010 ASP.Net Web 应用程序模板。当您导航到新选项卡时,状态会丢失。我的客户选项卡允许用户从 AspxGridView 过滤并选择一位客户。选定的客户 ID 存储在会话变量中,并用于在其他选项卡上显示相关客户数据:联系人、发票、任务等。我可以使用 SaveClientLayout。但我不知道如何在不重新查询数据库的情况下恢复网格数据。
我找到了本教程并实现了标题为 SessionPageStatePersister 的部分中的代码。我复制了代码并创建了 SessionPageStateAdapter 和 .browser 文件。我对如何访问此会话视图状态数据感到困惑。我需要有关如何保存视图状态并在用户访问多个其他页面后恢复它的帮助?
Currently I restore state by re-querying the database to fill a grid but the page loads too slowly. Instead, I'd like to save viewstate in session variables and restore it as a user re-visits the page. How is this done? Should I use the SessionPageStatePersister? This is not a postback situation or even a cross-page postback.
Background: I've used the VS 2010 ASP.Net Web Application template with a master page and multiple tabbed content pages. State is lost as you navigate to a new tab. My Customers tab allows the user to filter and select one customer from an AspxGridView. The selected Customer ID is stored in a session variable and used to display related customer data on other tabs: Contacts, Invoices, Tasks etc. I'm able to save and restore the Customer grid filter, sort and layout using SaveClientLayout. But I don't know how to restore the grid data without re-querying the database.
I found this tutorial and have implemented the code in the section titled SessionPageStatePersister. I've copied the code and created the SessionPageStateAdapter and the .browser file. I'm confused as to how to access this session viewstate data. I need help with how to save viewstate and restore it after the user has visited multiple other pages?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Viewstate 是管理会话状态的客户端方法。
它将代码注入到 html 渲染页面中。
因此,当用户关闭时,浏览器状态不会保留。
如果您想跨浏览器会话保存状态,有两种方法:
继续将其存储在数据库中。
如果您遇到性能问题,请考虑使用 ASP.NET 缓存
将您的信息存储在 cookie 中。
Viewstate is a client side way to manage session state.
It injects code inside html rendered page.
So when user close the browser state is not persisted.
If you want to save state across browser session you have two way:
continue to store it in database.
If you have performance issues consider using ASP.NET cache
store your informations in a cookie.