简体   繁体   中英

Can we avoid few of the CSS files which are there in master page to load in the content pages?

Basically what i want to say is can we decide among the list of css files defined in master page which one to load in content pages.

Generally whatever CSS and JS files we define in master pages we can see their behavior in content pages can we control this behavior

You can run through your registered links like this:

var links=this.Header.Controls.OfType<HtmlLink>();

typically, you can do that in the oninit of your page. Then you can add/remove/modify registered css or javascript.

I have a content area in my master page I call "AdditionalStyles", placed in the head section. This way any page using that master page can add its own style sheets.

Master page:

<head> 
...
<asp:ContentPlaceHolder runat="server" ID="additionalStyles"></asp:ContentPlaceHolder>
...
</head>

Child page:

<asp:Content ContentPlaceHolderID="additionalStyles" runat="server">
<link href="/css/specialstyle.css" rel="stylesheet" type="text/css" />
</asp:Content>

If certain pages require certain CSS files then have you thought about nested master pages?

Have 1 master page where all page inherit from then master pages below that, where there are more defined CSS files or more that are specific to a group of other pages.

And what is a problem? If you need to load different css's on some params (func params) use just a theming. Or just get in conclusion with your params and make differences in css's.

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