+1-888-365-2779
Try Now
More in this section

Forums / Designing with Sitefinity / front end - change theme via drop down

front end - change theme via drop down

12 posts, 0 answered
  1. Meister
    Meister avatar
    262 posts
    Registered:
    09 Nov 2007
    01 May 2008
    Link to this post
    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
  2. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    07 May 2008
    Link to this post
    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
  3. Jess
    Jess avatar
    3 posts
    Registered:
    21 Nov 2007
    12 Jun 2008
    Link to this post
    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.
  4. Sonya
    Sonya avatar
    231 posts
    Registered:
    24 Sep 2012
    13 Jun 2008
    Link to this post
    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
  5. dimiter
    dimiter avatar
    13 posts
    Registered:
    25 Apr 2007
    17 Apr 2009
    Link to this post
    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
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    17 Apr 2009
    Link to this post
    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.
  7. dimiter
    dimiter avatar
    13 posts
    Registered:
    25 Apr 2007
    17 Apr 2009
    Link to this post
    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?
  8. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    17 Apr 2009
    Link to this post
    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.
  9. dimiter
    dimiter avatar
    13 posts
    Registered:
    25 Apr 2007
    17 Apr 2009
    Link to this post
    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
  10. Dido
    Dido avatar
    149 posts
    Registered:
    24 Sep 2012
    21 Apr 2009
    Link to this post
    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.
  11. Jacques
    Jacques avatar
    427 posts
    Registered:
    28 Jun 2007
    14 Jul 2011
    Link to this post
    This solution no longer works in Sitefinity 4 because there is no more InternalPage. How would we go about implementing this solution now?
  12. Dido
    Dido avatar
    149 posts
    Registered:
    24 Sep 2012
    19 Jul 2011
    Link to this post
    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
Register for webinar
12 posts, 0 answered