开发者

asp.net - Include CSS file only one

开发者 https://www.devze.com 2023-03-13 01:36 出处:网络
I\'m stepping in to a project that has been going on for a few years. One of the issues I saw immediately is that CSS files are being included in the master pages, the aspx pages, user controls and mo

I'm stepping in to a project that has been going on for a few years. One of the issues I saw immediately is that CSS files are being included in the master pages, the aspx pages, user controls and more, and als开发者_如何学JAVAo style sheets are created and imporeted via aspx files, and not linked. (A mess, I know) It becomes impossible to debug styling issues.

What would be the best strategy for removing the double imports? Is there any built-in method to insure files are imported only once?

Thank you!


One way will be to have all CSS files embedded as resources then use Page.ClientScript.RegisterClientScriptResource.

Another way is leave the files as they are now and use Page.ClientScript.RegisterClientScriptBlock to include them after checking if already included by Page.ClientScript.IsClientScriptBlockRegistered giving it the unique key used in the Register method.

Either way, you'll have to remove the CSS includes from the .aspx itself and put it in the code behind.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号