ViewState 对象在母版页加载中丢失
我在内容页面的页面加载中分配 ViewState["something"] ,当我尝试访问母版页加载事件处理程序中的 ViewState 变量时,viewstate 变量丢失。任何人都可以指导我为什么会发生这种情况以及解决方案。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
也许(刚刚在网上找到)这是解决方案的提示:
在标题为 母版页和视图状态问题。 是否与母版页中的 Viewstate 关闭有关?
Maybe (just found it on the web) this is a hint to the solution:
Found this in a blog post titled MasterPage and viewstate issue. Could it have something to do with the Viewstate being turned off in the master page?
母版页和内容页不共享相同的 ViewState。
如果您尝试将内容从内容页传递到母版页,有几种选择:
- 在 HTTP 请求期间使用整个站点通用的 this.Context.Items
- 在母版页上创建一个公共属性,将 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