Is there a way to have a user control ensure its page has a certain css file?

106 Views Asked by At

(Please note that I'm not talking about this: How to make user controls know about css classes in ASP.NET )

I have some user controls which css styles comes from a small .css file. I would like to know if there is a way for the user control to tell any page it is placed in that the page needs to import this .css file.

What I'm trying to do is avoid forgetting to add a link to the .css file every time I add a usercontrol to a page by just having the control itself say "Hey, page that contains me, I need you to import this .css file if you haven't already".

1

There are 1 best solutions below

1
On BEST ANSWER

I would add the css in programatically from the user control itself. This questions gives a good example how

Adding StyleSheets Programmatically in Asp.Net

Therefore the containing pages don't need to know about the css.

Or i guess you could just add it in the usercontrols in some style tags. Depends on your cascade. That one feels a bit dirty to me - i wouldn't sully myself with such unpleasantness (he lies)