当我在包含viewstate的页面上使用或处理几分钟并重新加载页面时,我得到了这个错误:
Failed to load viewstate. The control tree into which viewstate is being loaded must match the control tree that was used to save viewstate during the previous request. For example, when adding controls dynamically, the controls added during a post-back must match the type and position of the controls added during the initial request.
通过设置页面设置enableviewstate= false,我得到了解决方案
但是,应用此操作后,viewstate变量在此页面上无法工作。
发布于 2013-09-13 06:21:05
在我的例子中,出现此问题是因为我创建了影响控件位置值的控件,因为它无法关闭该控件的标记。通过更正控件标记,它被更正了。
发布于 2013-03-02 07:28:12
原因可能是您在Page_Load中动态添加控件。也就是说,在Page_Load中添加一些网格,并将其视图状态保存到页面中,但是,当页面回发并解析ViewState时,引擎将无法为解析的ViewState找到相应的控件。
也就是说,Page_Load事件(由Page_Load处理)是在页面完全加载(即创建子程序、视图状态解析和应用)之后,而是在客户端事件(如单击、启动和呈现页面)之前触发的。
将动态控件添加到Page_Init中,并确保它们在每次创建时完全相同,即在第一个页面init上和回发后在页面init上都是相同的。
一个有用的链接ASP.NET页面生命周期
https://stackoverflow.com/questions/15171776
复制相似问题