Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7166167
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:22:10+00:00 2026-05-28T14:22:10+00:00

I’m learning ASP.net and I’ve been playing around with themes and master pages. I

  • 0

I’m learning ASP.net and I’ve been playing around with themes and master pages. I decided I wanted to change the theme of the website, and used the web.config solution (adding theme to web.config). What I want to do now is to be able to change the theme based on user and the selected theme by the user.

I have been unable to find any tutorials, all of them seem to show how to change separate contentpages, but I want to change the whole site theme.

How do you go about doing that, in the simplest way? I am not connected to a database atm., it’s just for practice 🙂

with kind regards

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T14:22:11+00:00Added an answer on May 28, 2026 at 2:22 pm

    Create a base page that you inherit all your pages from and set the theme in the OnPreInit event:

    public class ThemePage : System.Web.UI.Page
    {
        protected override void OnPreInit(EventArgs e)
        {
            SetTheme();            
    
            base.OnPreInit(e);
        }
    
        private void SetTheme()
        {
            this.Theme = ThemeSwitcher.GetCurrentTheme();
        }
    }
    

    Below is the ThemeSwitcher utility class that handles getting/saving the current theme and listing themes. Since you said you’re not using a database you can use Session:

    public class ThemeSwitcher
    {
        private const string ThemeSessionKey = "theme";
    
        public static string GetCurrentTheme()
        {
            var theme = HttpContext.Current.Session[ThemeSessionKey]
                as string;
    
            return theme ?? "Default";
        }
    
        public static void SaveCurrentTheme(string theme)
        {
            HttpContext.Current.Session[ThemeSessionKey]
                = theme;
        }
    
        public static string[] ListThemes()
        {
            return (from d in Directory.GetDirectories(HttpContext.Current.Server.MapPath("~/app_themes"))
                    select Path.GetFileName(d)).ToArray();
        }
    }
    

    You’ll want a page where you can change the theme. Add a dropdownlist with the following code behind:

    public partial class _Default : ThemePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                BindData();
            }
        }
    
        private void BindData()
        {
            var currentTheme = ThemeSwitcher.GetCurrentTheme();
    
            foreach (var theme in ThemeSwitcher.ListThemes())
            {
                var item = new ListItem(theme);
                item.Selected = theme == currentTheme;
                ddlThemes.Items.Add(item);
            }
        }
    
        protected void ddlThemes_SelectedIndexChanged(object sender, EventArgs e)
        {
            ThemeSwitcher.SaveCurrentTheme(ddlThemes.SelectedItem.Value);
            Response.Redirect("~/default.aspx");
        }       
    }
    

    You can download the sample application here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I used javascript for loading a picture on my website depending on which small
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.