4

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 also 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!

E.J. Brennan
  • 45,870
  • 7
  • 88
  • 116
Elad Lachmi
  • 10,406
  • 13
  • 71
  • 133

1 Answers1

2

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.

Shadow The GPT Wizard
  • 66,030
  • 26
  • 140
  • 208