简体   繁体   中英

How can I set my Page styles and themes without using Page.Theme property?

My page is designed using two style sheets, form.css and styles.css, and I want to dynamically set their path based on the domain name.

Here is the code I wrote to change them dynamically. It works, but flickering occurs before switching to the new theme, How can I set the page styles and themes without using the Page.Theme property?

On Client Side

$(document).ready(function () {
    function preloadFunc() {
        var foldername = '<%= theme%>';
        $('#lnkCssForm').attr('href', 'css/' + foldername + '/form.css');
        $('#lnkCssStyles').attr('href', 'css/' + foldername + '/styles.css');
    }
    window.onpaint = preloadFunc();
});

On Server Side (On Page preInit)

theme = Session["domainTheme"].ToString();

Why would you use javascript (and also on-dom-ready) for this? No wonder this causes "flicker". Why not output the path directly from the template/partial/whatever that outputs the head with the style?

<head>
   <link rel="stylesheet" type="text/css" href="css/<%= theme %>/form.css" media="all">
   <link rel="stylesheet" type="text/css" href="css/<%= theme %>/styles.css" media="all">
</head>

And what is the reason you don't want to use Page.Theme for this? It's exactly what this is meant for...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM