I'm trying to add this into an application I've already written, and am stuck.
I have two master pages: default.master and alternate.master. I would like to allow a user to switch back-and-forth between the two master pages as often as they want - the master pages yield two very different designs.
I have a BasePage class.
I add the links/linkbuttons to the master pages from a *.ascx file with it's own codefile.
Somewhere in all of this, I can't figure out where I handle changing the master pages.
In the .ascx file, I am using LinkButtons (for the moment):
Code:
<asp:Linkbutton id="btnDefault" commandArgument="default" onCommand="Change_Master" causesValidation="false" text="DEFAULT SKIN" runat='server'/>
and:
Code:
<asp:Linkbutton id="btnAlternate" commandArgument="alternate" onCommand="Change_Master" causesValidation="false" text="ALTERNATE SKIN" runat='server'/>
In the codefule for the .ascx, I am using this:
Code:
protected void Change_Master (object sender, CommandEventArgs e)
{
Session["Page_Master"] = e.CommandArgument.ToString();
this.Response.Redirect(this.Request.Url.ToString());
}
In the individual page classes, I can detect and display the content of the Session["Page_Master"] object in the OnLoad event, but cannot detect it in the OnPreInit event. In the OnPreInit event, if I try to apply the session object to change the page master, I get a 404 error for a page dependency not found.
I don't know if the BasePage class has a role to play, what it should be doing in the BasePage_PreInit event, or if I handle it all within the individual page classes...
I have tinkered with this for so long I have completely confused myself, and would appreciate any help or guidance in how to untangle this Gordian knot.
Thanks, and Happy New Year!
- Tinker