ViewState object lost in Master Page Load

…衆ロ難τιáo~ 提交于 2019-12-06 02:30:20

问题


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.


回答1:


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




回答2:


Maybe (just found it on the web) this is a hint to the solution:

Unless the MasterPage has its ViewState turned on, all controls below it would lose their state.

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?



来源:https://stackoverflow.com/questions/378381/viewstate-object-lost-in-master-page-load

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!