解决方法
I have an ascx that has some CSS in it… Is this considered bad practice?
是.理想情况下,CSS规则应该在一个单独的静态css文件中定义,该文件只能在主页的标题中加载一次.正文中的CSS不符合标准.
如果您在静态CSS文件上设置了良好的缓存规则,这将显着减少您通过网络传输的数据量,因为不需要为每个页面加载再次加载CSS规则.如果要在呈现某些相关ASCX文件时仅在头中包含此文件,请查看Neil Fenwick’s answer.
更新
无论出于何种原因,尼尔芬威克似乎已经删除了他的答案.希望他不介意我在这里复制它:
Definitely YES,it is possible.
I would recommend looking at a library like 07001 to manage your CSS and JS includes & dependencies.
Good examples for how to include given on ClientDependency codeplex page. Its good practice to organise your CSS and JS dependencies so that you can assert their requirement multiple times,but only emit the dependency in the output once.