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?
And what is the reason you don’t want to use
Page.Themefor this? It’s exactly what this is meant for…