views:

606

answers:

4

I want to avoid the duplication of stylesheet link tags in the output html when a user control is dropped onto an aspx page. However if you omit the stylesheet link tag you don't get design time support for the stylesheet.

Anybody know a way around this problem?

A: 

While that will impact the size of the HTML. I don't see it affecting the overall performance of your webpage. The browser will cache the CSS client side, so it should only be downloaded once.

Brian Schmitt
One case where it could affect the page is when the link tag is specified relative to the user control's position in the project. This happened to me when both the user control and css are in sub folders off the root, but not in the same folder. IIS will log a bunch of 404s
Kwan Cheng
A: 

Add the link tag until you're done using the VS designer, then comment/remove before moving on.

There is no way for it to reference the styles in the designer unless specified. I don't know any other way that this would work, but I've never used the VS designer in a ASP.NET application.

I still think your best and fastest option would be to add the reference, work your control, comment/remove later. It's sloppy and redundant to have extra link/script tags spread all over your page.

thismat
+2  A: 

I suggest seeing this thread:

How to make user controls know about CSS classes in ASP.NET.

Scott Whitlock
A: 

Use a custom designer to load the stylesheet as a resource and apply the style when you render the design time HTML.