Forums

Skip Navigation LinksHome / Developer Network / Forums / Sitefinity Older Versions (3.x): Designing with Sitefinity > front end - change theme via drop down

front end - change theme via drop down

  • Meister Intermediate avatar

    Posted on May 1, 2008 (permalink)

    is it possible to have a drop down on the front end site listing all the themes

    and whatever theme is selected, the site will use that design.
     
    the theme would have to be remember in a cookie for subsequent visits

    thanks

    Reply

  • Georgi Georgi admin's avatar

    Posted on May 7, 2008 (permalink)

    Hi Quade,

    You can take a look at the implementation of System.Web.UI.Page.PerformPreInit method:

    private void PerformPreInit()  
    {  
        this.OnPreInit(EventArgs.Empty);  
        this.InitializeThemes();  
        this.ApplyMasterPage();  
        this._preInitWorkComplete = true;  
    }  
     

    To programmatically set themes, please follow these steps:
    1. Create a new class in the  App_Code folder that inherits from Telerik.Cms.Web.InternalPage and override OnPreInit method. Enter your logic in this method (store information in cookie etc.).
      public class CustomPage : Telerik.Cms.Web.InternalPage  
      {  
          protected override void OnPreInit(EventArgs e)  
          {  
              base.OnPreInit(e);  
              this.Theme = "MyTheme";  
          }  
      }  
       
    2. Replace the declaration of InternalPage class with the name of your newly created class in the following file ~/Sitefinity/cmsentrypoint.aspx. The file should look like this:
      <%@ Page Language="C#" MasterPageFile="~/App_Master/Dummy.master" Inherits="CustomPage" %> 
       
    In this case we have set MyTheme dynamically as a theme of our site. Then you should create the dropdown box with your theme names as values.

    Sincerely yours,
    Georgi
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center

    Reply

  • Jess avatar

    Posted on Jun 12, 2008 (permalink)

    This solution sounds great but which "App_Code" folder are you referring to?  I can't find an "App_Code" folder in my site directory.

    Reply

  • Sonya Sonya admin's avatar

    Posted on Jun 13, 2008 (permalink)

    Hi Jessica Fonseca,

    You need to create one for the given project. This folder is generally used for adding source code to the project.

    Best wishes,
    Sonya
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center

    Reply

  • Posted on Apr 17, 2009 (permalink)

    Hi

    I have tried this code, but I got this error :

    Invalid Page request! The CMS entry point should never be called directly.

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.Web.HttpException: Invalid Page request! The CMS entry point should never be called directly.

    Source Error:

    Line 17:     protected override void OnPreInit(EventArgs e)
    Line 18:     {
    Line 19: base.OnPreInit(e);Line 20:         this.Theme = "Orange with left sidebar";
    Line 21:     }
     Plese could you help me maybe I am doing something wrong

    Kind regards

    Reply

  • Ivan Dimitrov Ivan Dimitrov admin's avatar

    Posted on Apr 17, 2009 (permalink)

    Hi dimiter,

    Give a try to this:

    1. Create a class in App_Code folder :

    Example ( with demonstrative purposes)

    namespace Telerik.Samples 
        public class ChangePage : InternalPage 
        { 
            public ChangePage() 
            { 
            } 
     
            protected override void OnPreInit(EventArgs e) 
            { 
                
                        base.OnPreInit(e); 
                        Page.Theme = "Orange with left sidebar"
      
            } 
        } 


    2. Change cmsentrypoint.aspx as below

    <%@ Page Inherits="Telerik.Samples.ChangePage" MasterPageFile="~/Sitefinity/Dummy.master" %> 


    Kind regards,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.

    Reply

  • Posted on Apr 17, 2009 (permalink)

    Hi
    My code is exactly the same but I still recieve this error.
    I am using this page like external sitefinity page is that correct?

    Reply

  • Ivan Dimitrov Ivan Dimitrov admin's avatar

    Posted on Apr 17, 2009 (permalink)

    Hello dimiter,

    You are inheriting from InternalPage, so this will work only from pages created under Sitefinity.

    Regards,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.

    Reply

  • Posted on Apr 17, 2009 (permalink)

    Hi

    if I inherit Page class it works fine , but  if I inherit InternalPage class raise this error
    I am using page as external page in sitefinity how can I use it as normal page

    Reply

  • Dido Dido admin's avatar

    Posted on Apr 21, 2009 (permalink)

    Hello dimiter,

    Creating a cookie in .NET is as easy as it can be. Sitefinity uses regular ASP.NET themes, so for pages that are not built with Sitefinity, you could use the standard ASP.NET way to change a theme.
    Here are some links to sources that explain how to achieve this:

    Kind regards,
    Dido
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.

    Reply

  • J.Hoventer Master avatar

    Posted on Jul 14, 2011 (permalink)

    This solution no longer works in Sitefinity 4 because there is no more InternalPage. How would we go about implementing this solution now?

    Reply

  • Dido Dido admin's avatar

    Posted on Jul 19, 2011 (permalink)

    Hello J.Hoventer,

     Sitefinity 4.0 now uses a modified way of handling themes. You can read about them in the documentation: http://www.sitefinity.com/documentation/designers-guide/creating-a-theme.aspx.
    There is a how-to article that explains how to set a page theme programatically

    It is desirable to use the UI for setting themes. Messing around with the page handler could cause problems.

    Regards,
    Dido
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

    Reply

  • Register for webinar
Skip Navigation LinksHome / Developer Network / Forums / Sitefinity Older Versions (3.x): Designing with Sitefinity > front end - change theme via drop down