0

アプリケーションに 2 つのマスター ページがあり、ドロップダウンの選択に基づいてマスター ページを変更しています。

あるマスターページを別のマスターページに変更しようとすると、

    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は2つのマスターページでも同じです

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 に答える