Setting an ASP.NET Master Page at runtime

前端 未结 6 1193
星月不相逢
星月不相逢 2021-02-04 15:45

I\'m working on a site which needs to be able to support two or more looks, changable at runtime. I\'d hoped to be able to handle the change with a CSS switch, but it looks like

6条回答
  •  北恋
    北恋 (楼主)
    2021-02-04 16:24

    I'm curious what decides how the page should look? Is it the user clicking a button to change the theme? Is it based on the URL that was used to get to the site?

    Code behind is supported in Master Pages, so you could put some logic in your one Master Page to decide what should be displayed.

    I've seen several sites set cookies based on user clicks (to change font size, or page width), and then have different CSS files applied based on the value of those cookies. If no cookie is present, display a default look and feel.

    EDIT:

    Another thought here, if you are simply trying to switch out CSS is to set your style tag to run at the server, and assign properties to it at run-time. Once again this would require the use of a single master page, and putting code the code-behind of the master page, probably in the PreInit event handler.

    Since I've never implemented this solution I'm not sure if the whole tag has to run at the server or not.

    
    
    
    
    
    

提交回复
热议问题