如何使用HttpContext访问当前页面的ViewState? [英] How could I access the ViewState of the current page using HttpContext?
本文介绍了如何使用HttpContext访问当前页面的ViewState?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用HttpContext访问当前页面的ViewState
How could I access the ViewState of the current page using HttpContext
我有一个需要实现的ViewStateUtil类:
I have a ViewStateUtil class that I'd need to implement:
public static T GetViewState<T>(ViewStateKey viewStateKey)
{
// how to implement it?! HttpContext.Current...?
}
推荐答案
private static T GetViewState<T>(string name)
{
return (T) ((BasePage)HttpContext.Current.CurrentHandler).PageViewState[name];
}
我添加了一个新的PageViewState属性,让我的所有页面都从BasePage继承以公开ViewState,然后可以获取或设置它.
I added a new PageViewState property and let all my pages inherit from my BasePage to expose ViewState then being able to get or set it.
这篇关于如何使用HttpContext访问当前页面的ViewState?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文