ViewState的对象母版页装载过程中丢失 [英] ViewState object lost in Master Page Load
问题描述
我在内容页的页面加载分配的ViewState [东西],当我尝试访问母版页Load事件处理程序的ViewState的变量,视图状态变量是lost.Can有人指导我为什么发生这种情况和解决方案。
I am assigning ViewState["something"] in Page Load of content page and when I try to access the ViewState variable in Master Page Load event handler, the viewstate variable is lost.Can anyone guide me why this is happening and the solution.
推荐答案
母版页和内容页不共享相同的ViewState。
如果你正试图从内容页的东西传递给母版页有几个选择:
- 使用this.Context.Items该HTTP请求
- 使母版页上的公共属性,从内容页投this.Master到母版页类,并设置属性
- 使用会话
Master pages and content pages do not share the same ViewState.
If you are trying to pass something from the content page to the master page there are a couple of alternatives:
- use this.Context.Items that is common to the entire site during an HTTP request
- make a public property on the master page, cast this.Master from the content page to the master page class and set the property
- use Session
这篇关于ViewState的对象母版页装载过程中丢失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!