I have two master pages in my ASP.NET application. One for regular use, and another for printing. I use a session parameter to see if the application is currently in print mode or not:
method Global.Application_PreRequestHandlerExecute(src: System.Object; e: EventArgs);
begin
var p: System.Web.UI.Page := System.Web.UI.Page(self.Context.Handler);
if p <> nil then begin
p.PreInit += new EventHandler(page_PreInit)
end
end;
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 p.Master <> nil then
begin
if Session['P'].ToString = '1' then
p.MasterPageFile := '~/Print.Master'
else
p.MasterPageFile := '~/Site.Master';
end;
end;
I have one button on my normal page which sets Session['P']
to '1'
, and another on my print master page which sets Session['P']
to '0'
. Now, my problem is that after the I have changed the session parameter in my code, the page is rendered using the obsolete master page, and not the current one. The user has to hit F5 to see the correct page. It almost seems like my page_PreInit()
event is fired before buttonClick()
. So, what can I do?