Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9007181
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:37:09+00:00 2026-06-16T01:37:09+00:00

I have created two master pages for my website. one for normal use, and

  • 0

I have created two master pages for my website. one for normal use, and another for print. On my normal master page, I have a button which sets Session['P'] to '1'. On the print master page, I have another button which sets Session['P'] to '0'. And in my Global.asax.pas, I have the following code to determine which master page to use:

method Global.page_PreInit(sender: System.Object; e: EventArgs);
begin
  var p: System.Web.UI.Page := System.Web.UI.Page(self.Context.Handler);
  if p <> nil then   
    if Session['P'].ToString = '1' then
      p.MasterPageFile := '~/Print.Master'
    else
      p.MasterPageFile := '~/Site.Master'; 
end;

After settings Session['P'], I need to reload the page for its master to change. I need the view state of all my controls to be preserved, and thus can’t use Response.Redirect(). I tried using Server.Transfer(Request.Url.AbsolutePath, True);, but it raises the following exception. How can I work around it?

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T01:37:10+00:00Added an answer on June 16, 2026 at 1:37 am

    I am afraid that there is no work around – you change the controls tree of the viewstate after the post back.

    You can only disable the viewstate on the controls on the master pages, the controls that conflict with the two master pages.

    The general idea is that you disable the viewstate on the controls that have the problem, or you try to use the same control on the two master pages, with the same ids.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a master page (Site.master) which contains the code to display a
I am trying to use two master pages one for the entire site collection
I had created a webpage using asp.net mvc3 razor. I have two master pages
I am using SQL Server 2008 R2. I have created two different databases Master
I have created two Pages Page1.xaml and Page2.xaml in windows8 metro apps. I have
I have created two DbContexts, one is for application configuration, the second is for
I have created two folders layout and layout-land with two xml files, one for
I have created two forms in my Windows Application. One Form acts as a
I have created two JavaScript files. One file is "validators.js" and the other is
I have a Visual Studio C# .NET project. I have two master templates. One

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.