将 SavePageStateToPersistenceMedium() 用于母版页 ASP.NET
请参考主题 http://www.codeproject.com/KB/viewstate/SaveViewState .aspx。本主题演示如何通过服务器将 ViewState 保存到文件系统,以使 ViewState 在往返时非常小。作者通过继承System.Web.UI.Page创建了一个类BasePage,所有的页面都派生于这个类。
我正在开发的网站使用母版页,所有页面均源自该母版页。当我尝试重写 SavePageStateToPersistenceMedium()
时,会生成编译错误,表明 System.Web.UI.MasterPage 中没有可重写的此类方法。
我该如何解决这个问题?
Please refer to the topic http://www.codeproject.com/KB/viewstate/SaveViewState.aspx. The topic demonstrates how you can save ViewState to a file system over server so as to make ViewState very small on roundtrips. The author had created a class BasePage by inheriting System.Web.UI.Page and all the pages are derived from this class.
The site I am developing uses a masterpage and all the pages are derived from this masterpage. When I try to override SavePageStateToPersistenceMedium()
, a compilation error is generated indicating that there is no such method to override within System.Web.UI.MasterPage.
How could I solve this problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我已经找到了解决方案。实际上,aspx页面是从System.Web.UI.Page派生的,而masterpage是从Control类派生的。 SavePageStateToPersistenceMedium() 方法仅在 aspx 页面中可用,在母版页中不可用。您必须在每个 aspx 页面中重写此方法,或者创建您自己的从 Page 类派生的基类,然后重写该方法。
I have found the solution. Actually the aspx page is derived from System.Web.UI.Page while the masterpage is derived from Control class. There the method SavePageStateToPersistenceMedium() is available within aspx page only not in master page. You have to override this method within each aspx page or create your own base class derived from Page class and then override the method.
使用 PageStatePersister 覆盖会更容易无需基类即可更改所有页面上的 ViewState 持久性机制的方法。
Milan Negovan 写了一篇很好的博客文章,介绍了使用 PageStatePersister 的不同选项,并提供了一些附加链接。
Using a PageStatePersister override would be an easier way to change the ViewState persistance mechanism on all pages without requiring a base class.
Milan Negovan has written a good blog post on the different options using the PageStatePersister, with some additional links.