0

我的应用程序中有两个母版页,我正在根据下拉选择更改我的母版页。

当我试图在一个母版页之间切换到另一个母版页时,我得到了

    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 在两个母版页中也相同

4

1 回答 1

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
  }
}
于 2013-08-27T07:43:13.683 回答