我的应用程序中有两个母版页,我根据下拉选项更改母版页。
当我尝试在一个母版页之间切换到另一个母版页时,我正在
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 :(得分: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
}
}