Getting VS2008 to display CSS in Web User Controls

April 22 2010

Ever created a Web User Control in Visual Studio 2008 and noticed it doesn't render the control using CSS.  It doesn't by design, because the IDE doesn't know where the control will be dropped.  The page it's inserted into determines the style to use.  One way to see the styled WUC is to drop it on a page with existing styles (either inline or linked), but that can be a PITA when all you want to see is the style of that control.


When reading about how to get intellisense in pages with jquery a while back I came across the following method

<% if (false) { %>
<script type="text/javascript" src="/scripts/jquery.js" />
<% } %>

Which works wonderfully.  The same can be applied for stylesheets in user controls.

<% if (false) { %>
<link rel="stylesheet" type="text/css" href="/styles/site.css" />
<% } %>

Because false never evaluates to true, the html is never actually included in page, but while in design, the design picks up on it and styles your pages

Post a comment

comments powered by Disqus