2013-08-27 125 views
0

我的应用程序中有两个母版页,我正在根据下拉选择更改母版页。无法加载Viwstate错误

当我试图一个母版页之间切换到其他的我越来越

HttpException (0x80004005): 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.] 

而且我不加入任何控件动态了。唯一的区别是我有一些图像控件在页面中设置为runat =“server”。但是他们的Id在两个主页面中也是相同的

回答

0

使用查询字符串对同一页面执行Response.Redirect。然后在Page_Load中,根据查询字符串更改母版页。 更改母版页不能在回发中发生。

实施例:

void uxMasterPage_SelectedIndexChanged(object sender, EventArgs e) 
{ 
    Response.Redirect("MyPage.aspx?mp=2"); 
} 

void Page_Load(object sender, EventArgs e) 
{ 
    if(Request.QueryString["mp"]=="2") 
    { 
    //Change master page 
    } 
} 
+0

实际上我实现我的变化主页逻辑通过其中我正在继承为我的网页的一类上preinit方法覆盖 – Nagaraj