简体   繁体   中英

How to get Visual Studio's designer to render CSS correctly in an ASP.NET Web User Control?

When developing a web user control, I'm styling everything with CSS. Whenever I look at the control in the designer, none of the CSS is rendered, or course, because I'm not looking at it in the context of the page where my link element is declared to my CSS file. Plus, Visual Studio will include a warning:

The class or CssClass value is not defined.

for every class attribute I use.

I can get the designer to render the CSS if I include a link element in the control itself, but then I have duplicate link elements scattered throughout my pages.

Is there any way to get the designer to play nice with my CSS in a web control without injecting duplicate link elements everywhere?

Sadly at the moment, I think that's the best you're going to get as seen here .

The only good news I can see is this Connect Issue which is "Closed - Postponed", so they may well be thinking about it.

The issue you've got is that you can make a control display very differently depending on the CSS rules applied with the styles - so one style sheet or a combination of parent tags could make (for example) labels appear above their form elements, and another beside them - which would you want to display when you are viewing the User control out of the page context?

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