Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Create a base page that you inherit all your pages from and set the theme in the OnPreInit event:</p> <pre><code>public class ThemePage : System.Web.UI.Page { protected override void OnPreInit(EventArgs e) { SetTheme(); base.OnPreInit(e); } private void SetTheme() { this.Theme = ThemeSwitcher.GetCurrentTheme(); } } </code></pre> <p>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:</p> <pre><code>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(); } } </code></pre> <p>You'll want a page where you can change the theme. Add a dropdownlist with the following code behind:</p> <pre><code>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"); } } </code></pre> <p>You can download the sample application <a href="http://storage.onfabrik.com/6724b018c1dfea1e/WebFormsThemeSwitcher.zip" rel="nofollow">here</a>.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload