Change template dynamically
I'd like to switch between two templates dynamically. For example, say I have two templates: Guest.Master and Authenticated.Master.
Outside SF, I've set up a Page_PreInit via the Application_PreRequestHandlerExecute in the Global.asax that would switch the master page (like below). The templates would be known to (and hard-coded in) the code. The templates would also contain the same ContentPlaceHolders.
protected void Application_PreRequestHandlerExecute(object src, EventArgs e) Page p = this.Context.Handler as Page; if (p != null) p.PreInit += new EventHandler(Page_PreInit);protected void Page_PreInit(object sender, EventArgs) if (IsUserAuthenticated) Page p = Context.Handler as Page; p.MasterPageFile = "~/MasterPages/Authenticated.master"; Hi Eric,
It would not be possible to switch any page parameters without saving changes made to objects that have been retrieved with a given manager and then committing the transaction. We are considering some options to make such changes during initialization, but in BETA it is not possible to change the theme/template without saving the changes.
Regards,
Ivan Dimitrov
the Telerik team
I probably should have tried it out first before bothering anyone here, it works pretty smoothly.
The Context.Handler is a Telerik.Sitefinity.Web.UI.SitefinityRadPage, which inherits from Telerik.Web.UI.RadAjaxPage, which inherits from System.Web.UI.Page, which has the MasterPageFile property which is settable in the PreInit event.
protected void Application_PreRequestHandlerExecute(object src, EventArgs e) Page p = Context.Handler as Page; if (p != null) p.PreInit += Page_PreInit;private void Page_PreInit(object sender, EventArgs e) Page p = Context.Handler as Page; if (p.MasterPageFile == "/Guest.Master" && DateTime.Now.Minute % 2 == 0) p.MasterPageFile = "/Auth.Master";