<?xml version="1.0" encoding="ISO-8859-1"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Egil Hansen &#187; CSS</title>
	<atom:link href="http://egilhansen.com/category/css/feed/" rel="self" type="application/rss+xml" />
	<link>http://egilhansen.com</link>
	<description>.NET, Windows, ASP.Net, scripts</description>
	<lastBuildDate>Thu, 04 Feb 2010 13:32:18 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How to take control of style sheets in ASP.NET Themes with the StylePlaceholder and Style control</title>
		<link>http://egilhansen.com/2008/11/30/how-to-take-control-of-style-sheets-in-aspnet-themes-with-the-styleplaceholder-and-style-control/</link>
		<comments>http://egilhansen.com/2008/11/30/how-to-take-control-of-style-sheets-in-aspnet-themes-with-the-styleplaceholder-and-style-control/#comments</comments>
		<pubDate>Sun, 30 Nov 2008 11:22:49 +0000</pubDate>
		<dc:creator>Egil Hansen</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[CSS]]></category>

		<guid isPermaLink="false">http://www.egil.dk/?p=83</guid>
		<description><![CDATA[The problem is pretty simple. When using ASP.NET Themes you do not have much say in how your style sheets are rendered to the page.
The render engine adds all the style sheets you have in your themes folder in alphabetic order, using the &#60;link href=&#8221;&#8230;&#8221;?  notation.
We all know the order of the style sheets [...]]]></description>
			<content:encoded><![CDATA[<p>The problem is pretty simple. When using ASP.NET Themes you do not have much say in how your style sheets are rendered to the page.</p>
<p>The render engine adds all the style sheets you have in your themes folder in alphabetic order, using the &lt;link href=&#8221;&#8230;&#8221;?  notation.</p>
<p>We all know the order of the style sheets are important, luckily asp.net&#8217;s shortcomings can be circumvented by prefixing the style sheets with 01, 02, &#8230; , 99, and thus forcing the order you want (see Rusty Swayne <a href="http://rustyswayne.com/post.aspx?id=cba116ea-b672-4c90-9f4e-18b70ca2f50a">blog post</a> on the technique for more information).</p>
<p>This is especially important if you use a reset style sheet, which I highly recommend; it makes it much easier to style a site in a consistent form across browsers (take a look at <a href="http://meyerweb.com/eric/thoughts/2007/05/01/reset-reloaded/">Reset Reloaded from Eric Meyer</a>).</p>
<p>You also miss out of the possibility to specify a media type (e.g. screen, print, projection, braille, speech). And if you prefer to include style sheets using the @import method, you are also left out in the cold.</p>
<p>Another missing option is Conditional Comment, which is especially useful if you use an &#8220;ie-fix.css&#8221; style sheet.</p>
<p>Before I explain how the StylePlaceHolder and Style control resolve the above issues, credit where credit is due, my solution is inspired by <a href="http://www.dentaku.com/2007/01/take-control-over-stylesheet-order-and-media-when-using-asp-net-2-0-themes.aspx">Per Zimmermann&#8217;s blog post</a> on the subject.</p>
<p>The StylePlaceHolder control is placed in the header section of your master page or page. It can host one or more Style controls, and will remove styles added by the render engine by default, and add its own (it will only remove styles added from the current active theme).</p>
<p>The Style control can both host inline styles in-between it&#8217;s opening and closing tags and a reference to a external style sheet file through its CssUrl property. Through other properties you control how the style sheet it renders to the page.</p>
<p>Let me show an example. Consider a simple web site project with a master page and a theme with three style sheets &#8211; 01reset.css, 02style.css, 99iefix.cs. Note: I have named them using prefixing technique described earlier, as it makes for a better design time experience. Also, the tag prefix of the custom controls is &#8220;ass:&#8221;.</p>
<p>In the master page&#8217;s header section, add:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ass:StylePlaceHolder</span> <span style="color: #000066;">ID</span>=<span style="color: #ff0000;">&quot;StylePlaceHolder1&quot;</span> <span style="color: #000066;">runat</span>=<span style="color: #ff0000;">&quot;server&quot;</span> <span style="color: #000066;">SkinID</span>=<span style="color: #ff0000;">&quot;ThemeStyles&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></div></div>

<p>In your theme directory, add a skin file (e.g. Styles.skin) and add the following content:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ass:StylePlaceHolder</span> <span style="color: #000066;">runat</span>=<span style="color: #ff0000;">&quot;server&quot;</span> <span style="color: #000066;">SkinId</span>=<span style="color: #ff0000;">&quot;ThemeStyles&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ass:Style</span> <span style="color: #000066;">CssUrl</span>=<span style="color: #ff0000;">&quot;~/App_Themes/Default/01reset.css&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ass:Style</span> <span style="color: #000066;">CssUrl</span>=<span style="color: #ff0000;">&quot;~/App_Themes/Default/02style.css&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ass:Style</span> <span style="color: #000066;">CssUrl</span>=<span style="color: #ff0000;">&quot;~/App_Themes/Default/99iefix.css&quot;</span> <span style="color: #000066;">ConditionCommentExpression</span>=<span style="color: #ff0000;">&quot;[if IE]&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ass:StylePlaceHolder<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>That is basically it. There are a more properties on the Style control that can be used to control the rendering, but this is the basic setup. With that in place, you can easily add another theme and replace all the styles, since you only need to include a different skin file.</p>
<p>The following is the code for the Style control:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">using</span> <span style="color: #008080;">System.ComponentModel</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Security.Permissions</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Web</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Web.UI</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #000000;">&#91;</span>assembly<span style="color: #008000;">:</span> TagPrefix<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Assimilated.Extensions.Web.Controls&quot;</span>, <span style="color: #666666;">&quot;ass&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
<span style="color: #0600FF;">namespace</span> Assimilated.<span style="color: #0000FF;">WebControls</span>.<span style="color: #0000FF;">Stylesheet</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #000000;">&#91;</span>AspNetHostingPermission<span style="color: #000000;">&#40;</span>SecurityAction.<span style="color: #0000FF;">Demand</span>, Level <span style="color: #008000;">=</span> AspNetHostingPermissionLevel.<span style="color: #0000FF;">Minimal</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
    <span style="color: #000000;">&#91;</span>AspNetHostingPermission<span style="color: #000000;">&#40;</span>SecurityAction.<span style="color: #0000FF;">InheritanceDemand</span>, Level <span style="color: #008000;">=</span> AspNetHostingPermissionLevel.<span style="color: #0000FF;">Minimal</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
    <span style="color: #000000;">&#91;</span>DefaultProperty<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;CssUrl&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
    <span style="color: #000000;">&#91;</span>ParseChildren<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">true</span>, <span style="color: #666666;">&quot;InlineStyle&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
    <span style="color: #000000;">&#91;</span>PersistChildren<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">false</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
    <span style="color: #000000;">&#91;</span>ToolboxData<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;&lt;{0}:Style runat=<span style="color: #008080; font-weight: bold;">\&quot;</span>server<span style="color: #008080; font-weight: bold;">\&quot;</span>&gt;&lt;/{0}:Style&gt;&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
    <span style="color: #000000;">&#91;</span>Themeable<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
    <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> Style <span style="color: #008000;">:</span> Control
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">public</span> Style<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #008080; font-style: italic;">// set default value... for some reason the DefaultValue attribute do</span>
            <span style="color: #008080; font-style: italic;">// not set this as I would have expected.</span>
            TargetMedia <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;All&quot;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #008080;">#region Properties</span>
&nbsp;
        <span style="color: #000000;">&#91;</span>Browsable<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #000000;">&#91;</span>Category<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Style sheet&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #000000;">&#91;</span>DefaultValue<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #000000;">&#91;</span>Description<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;The url to the style sheet.&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #000000;">&#91;</span>UrlProperty<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;*.css&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">string</span> CssUrl
        <span style="color: #000000;">&#123;</span>
            get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #000000;">&#91;</span>Browsable<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #000000;">&#91;</span>Category<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Style sheet&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #000000;">&#91;</span>DefaultValue<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;All&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #000000;">&#91;</span>Description<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;The target media(s) of the style sheet. See http://www.w3.org/TR/REC-CSS2/media.html for more information.&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">string</span> TargetMedia
        <span style="color: #000000;">&#123;</span>
            get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #000000;">&#91;</span>Browsable<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #000000;">&#91;</span>Category<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Style sheet&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #000000;">&#91;</span>DefaultValue<span style="color: #000000;">&#40;</span>EmbedType.<span style="color: #0000FF;">Link</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #000000;">&#91;</span>Description<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Specify how to embed the style sheet on the page.&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #0600FF;">public</span> EmbedType Type
        <span style="color: #000000;">&#123;</span>
            get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #000000;">&#91;</span>Browsable<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">false</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #000000;">&#91;</span>PersistenceMode<span style="color: #000000;">&#40;</span>PersistenceMode.<span style="color: #0000FF;">InnerDefaultProperty</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">string</span> InlineStyle
        <span style="color: #000000;">&#123;</span>
            get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #000000;">&#91;</span>Browsable<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #000000;">&#91;</span>Category<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Conditional comment&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #000000;">&#91;</span>DefaultValue<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #000000;">&#91;</span>Description<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Specifies a conditional comment expression to wrap the style sheet in. See http://msdn.microsoft.com/en-us/library/ms537512.aspx&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">string</span> ConditionalCommentExpression
        <span style="color: #000000;">&#123;</span>
            get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #000000;">&#91;</span>Browsable<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #000000;">&#91;</span>Category<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Conditional comment&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #000000;">&#91;</span>DefaultValue<span style="color: #000000;">&#40;</span>CommentType.<span style="color: #0000FF;">DownlevelHidden</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #000000;">&#91;</span>Description<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Whether to reveal the conditional comment expression to downlevel browsers. Default is to hide. See http://msdn.microsoft.com/en-us/library/ms537512.aspx&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #0600FF;">public</span> CommentType ConditionalCommentType
        <span style="color: #000000;">&#123;</span>
            get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #000000;">&#91;</span>Browsable<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #000000;">&#91;</span>Category<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Behavior&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">override</span> <span style="color: #FF0000;">string</span> SkinID <span style="color: #000000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #008080;">#endregion</span>
&nbsp;
        <span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">override</span> <span style="color: #0600FF;">void</span> Render<span style="color: #000000;">&#40;</span>HtmlTextWriter writer<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>            
            <span style="color: #008080; font-style: italic;">// add empty line to make output pretty</span>
            writer.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">// prints out begin condition comment tag</span>
            <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #008000;">!</span><span style="color: #FF0000;">string</span>.<span style="color: #0000FF;">IsNullOrEmpty</span><span style="color: #000000;">&#40;</span>ConditionalCommentExpression<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
                writer.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span>ConditionalCommentType <span style="color: #008000;">==</span> CommentType.<span style="color: #0000FF;">DownlevelRevealed</span> <span style="color: #008000;">?</span> <span style="color: #666666;">&quot;&lt;!{0}&gt;&quot;</span> <span style="color: #008000;">:</span> <span style="color: #666666;">&quot;&lt;!--{0}&gt;&quot;</span>,
                                 ConditionalCommentExpression<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #008000;">!</span><span style="color: #FF0000;">string</span>.<span style="color: #0000FF;">IsNullOrEmpty</span><span style="color: #000000;">&#40;</span>CssUrl<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>               
                <span style="color: #008080; font-style: italic;">// add shared attribute</span>
                writer.<span style="color: #0000FF;">AddAttribute</span><span style="color: #000000;">&#40;</span>HtmlTextWriterAttribute.<span style="color: #0000FF;">Type</span>, <span style="color: #666666;">&quot;text/css&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
                <span style="color: #008080; font-style: italic;">// render either import or link tag</span>
                <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>Type <span style="color: #008000;">==</span> EmbedType.<span style="color: #0000FF;">Link</span><span style="color: #000000;">&#41;</span>
                <span style="color: #000000;">&#123;</span>
                    <span style="color: #008080; font-style: italic;">// &lt;link href=\&quot;{0}\&quot; type=\&quot;text/css\&quot; rel=\&quot;stylesheet\&quot; media=\&quot;{1}\&quot; /&gt;</span>
                    writer.<span style="color: #0000FF;">AddAttribute</span><span style="color: #000000;">&#40;</span>HtmlTextWriterAttribute.<span style="color: #0000FF;">Href</span>, ResolveUrl<span style="color: #000000;">&#40;</span>CssUrl<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                    writer.<span style="color: #0000FF;">AddAttribute</span><span style="color: #000000;">&#40;</span>HtmlTextWriterAttribute.<span style="color: #0000FF;">Rel</span>, <span style="color: #666666;">&quot;stylesheet&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                    writer.<span style="color: #0000FF;">AddAttribute</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;media&quot;</span>, TargetMedia<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                    writer.<span style="color: #0000FF;">RenderBeginTag</span><span style="color: #000000;">&#40;</span>HtmlTextWriterTag.<span style="color: #0000FF;">Link</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                    writer.<span style="color: #0000FF;">RenderEndTag</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #000000;">&#125;</span>
                <span style="color: #0600FF;">else</span>
                <span style="color: #000000;">&#123;</span>
                    <span style="color: #008080; font-style: italic;">// &lt;style type=&quot;text/css&quot;&gt;@import &quot;modern.css&quot; screen;&lt;/style&gt;</span>
                    writer.<span style="color: #0000FF;">RenderBeginTag</span><span style="color: #000000;">&#40;</span>HtmlTextWriterTag.<span style="color: #0000FF;">Style</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                    writer.<span style="color: #0000FF;">Write</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;@import <span style="color: #008080; font-weight: bold;">\&quot;</span>{0}<span style="color: #008080; font-weight: bold;">\&quot;</span> {1};&quot;</span>, ResolveUrl<span style="color: #000000;">&#40;</span>CssUrl<span style="color: #000000;">&#41;</span>, TargetMedia<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                    writer.<span style="color: #0000FF;">RenderEndTag</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #000000;">&#125;</span>
            <span style="color: #000000;">&#125;</span>
&nbsp;
            <span style="color: #0600FF;">if</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">!</span><span style="color: #FF0000;">string</span>.<span style="color: #0000FF;">IsNullOrEmpty</span><span style="color: #000000;">&#40;</span>InlineStyle<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                <span style="color: #008080; font-style: italic;">// &lt;style type=&quot;text/css&quot;&gt;... inline style ... &lt;/style&gt;</span>
                writer.<span style="color: #0000FF;">AddAttribute</span><span style="color: #000000;">&#40;</span>HtmlTextWriterAttribute.<span style="color: #0000FF;">Type</span>, <span style="color: #666666;">&quot;text/css&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                writer.<span style="color: #0000FF;">RenderBeginTag</span><span style="color: #000000;">&#40;</span>HtmlTextWriterTag.<span style="color: #0000FF;">Style</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                writer.<span style="color: #0000FF;">Write</span><span style="color: #000000;">&#40;</span>InlineStyle<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                writer.<span style="color: #0000FF;">RenderEndTag</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">// prints out end condition comment tag</span>
            <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #008000;">!</span><span style="color: #FF0000;">string</span>.<span style="color: #0000FF;">IsNullOrEmpty</span><span style="color: #000000;">&#40;</span>ConditionalCommentExpression<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                <span style="color: #008080; font-style: italic;">// add empty line to make output pretty</span>
                writer.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                writer.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span>ConditionalCommentType <span style="color: #008000;">==</span> CommentType.<span style="color: #0000FF;">DownlevelRevealed</span> <span style="color: #008000;">?</span> <span style="color: #666666;">&quot;&lt;![endif]&gt;&quot;</span> <span style="color: #008000;">:</span> <span style="color: #666666;">&quot;&lt;![endif]--&gt;&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">enum</span> EmbedType
    <span style="color: #000000;">&#123;</span>        
        Link <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span>,
        Import <span style="color: #008000;">=</span> <span style="color: #FF0000;">1</span>,
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">enum</span> CommentType
    <span style="color: #000000;">&#123;</span>
        DownlevelHidden <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span>,
        DownlevelRevealed <span style="color: #008000;">=</span> <span style="color: #FF0000;">1</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>And the code for the StylePlaceHolder control:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Collections.Generic</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.ComponentModel</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Linq</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Security.Permissions</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Web</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Web.UI</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Web.UI.HtmlControls</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #000000;">&#91;</span>assembly<span style="color: #008000;">:</span> TagPrefix<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Assimilated.Extensions.Web.Controls&quot;</span>, <span style="color: #666666;">&quot;ass&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
<span style="color: #0600FF;">namespace</span> Assimilated.<span style="color: #0000FF;">WebControls</span>.<span style="color: #0000FF;">Stylesheet</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #000000;">&#91;</span>AspNetHostingPermission<span style="color: #000000;">&#40;</span>SecurityAction.<span style="color: #0000FF;">Demand</span>, Level <span style="color: #008000;">=</span> AspNetHostingPermissionLevel.<span style="color: #0000FF;">Minimal</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
    <span style="color: #000000;">&#91;</span>AspNetHostingPermission<span style="color: #000000;">&#40;</span>SecurityAction.<span style="color: #0000FF;">InheritanceDemand</span>, Level <span style="color: #008000;">=</span> AspNetHostingPermissionLevel.<span style="color: #0000FF;">Minimal</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
    <span style="color: #000000;">&#91;</span>DefaultProperty<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;SkinID&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
    <span style="color: #000000;">&#91;</span>ToolboxData<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;&lt;{0}:StylePlaceHolder runat=<span style="color: #008080; font-weight: bold;">\&quot;</span>server<span style="color: #008080; font-weight: bold;">\&quot;</span> SkinID=<span style="color: #008080; font-weight: bold;">\&quot;</span>ThemeStyles<span style="color: #008080; font-weight: bold;">\&quot;</span>&gt;&lt;/{0}:StylePlaceHolder&gt;&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
    <span style="color: #000000;">&#91;</span>ParseChildren<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">true</span>, <span style="color: #666666;">&quot;Styles&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
    <span style="color: #000000;">&#91;</span>Themeable<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
    <span style="color: #000000;">&#91;</span>PersistChildren<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">false</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
    <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> StylePlaceHolder <span style="color: #008000;">:</span> Control
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">private</span> List<span style="color: #008000;">&lt;</span>Style<span style="color: #008000;">&gt;</span> _styles<span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #000000;">&#91;</span>Browsable<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #000000;">&#91;</span>Category<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Behavior&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #000000;">&#91;</span>DefaultValue<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;ThemeStyles&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">override</span> <span style="color: #FF0000;">string</span> SkinID <span style="color: #000000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #000000;">&#91;</span>Browsable<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">false</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #0600FF;">public</span> List<span style="color: #008000;">&lt;</span>Style<span style="color: #008000;">&gt;</span> Styles
        <span style="color: #000000;">&#123;</span>
            get
            <span style="color: #000000;">&#123;</span>
                <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>_styles <span style="color: #008000;">==</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
                    _styles <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> List<span style="color: #008000;">&lt;</span>Style<span style="color: #008000;">&gt;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #0600FF;">return</span> _styles<span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">override</span> <span style="color: #0600FF;">void</span> CreateChildControls<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>_styles <span style="color: #008000;">==</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
                return<span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">// add child controls</span>
            Styles.<span style="color: #0600FF;">ForEach</span><span style="color: #000000;">&#40;</span>Controls.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">override</span> <span style="color: #0600FF;">void</span> OnLoad<span style="color: #000000;">&#40;</span>EventArgs e<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">base</span>.<span style="color: #0000FF;">OnLoad</span><span style="color: #000000;">&#40;</span>e<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">// get notified when page has finished its load stage</span>
            Page.<span style="color: #0000FF;">LoadComplete</span> <span style="color: #008000;">+=</span> Page_LoadComplete<span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">void</span> Page_LoadComplete<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> sender, EventArgs e<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #008080; font-style: italic;">// only remove if the page is actually using themes</span>
            <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #008000;">!</span><span style="color: #FF0000;">string</span>.<span style="color: #0000FF;">IsNullOrEmpty</span><span style="color: #000000;">&#40;</span>Page.<span style="color: #0000FF;">StyleSheetTheme</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">||</span> <span style="color: #008000;">!</span><span style="color: #FF0000;">string</span>.<span style="color: #0000FF;">IsNullOrEmpty</span><span style="color: #000000;">&#40;</span>Page.<span style="color: #0000FF;">Theme</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                <span style="color: #008080; font-style: italic;">// Make sure only to remove style sheets from the added by</span>
                <span style="color: #008080; font-style: italic;">// the runtime form the current theme.</span>
                var themePath <span style="color: #008000;">=</span> <span style="color: #FF0000;">string</span>.<span style="color: #0000FF;">Format</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;~/App_Themes/{0}&quot;</span>,
                                              <span style="color: #008000;">!</span><span style="color: #FF0000;">string</span>.<span style="color: #0000FF;">IsNullOrEmpty</span><span style="color: #000000;">&#40;</span>Page.<span style="color: #0000FF;">StyleSheetTheme</span><span style="color: #000000;">&#41;</span>
                                                  <span style="color: #008000;">?</span> Page.<span style="color: #0000FF;">StyleSheetTheme</span>
                                                  <span style="color: #008000;">:</span> Page.<span style="color: #0000FF;">Theme</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
                <span style="color: #008080; font-style: italic;">// find all existing stylesheets in header</span>
                var removeCandidate <span style="color: #008000;">=</span> Page.<span style="color: #0000FF;">Header</span>.<span style="color: #0000FF;">Controls</span>.<span style="color: #0000FF;">OfType</span><span style="color: #008000;">&lt;</span>HtmlLink<span style="color: #008000;">&gt;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
                    .<span style="color: #0000FF;">Where</span><span style="color: #000000;">&#40;</span>link <span style="color: #008000;">=&gt;</span> link.<span style="color: #0000FF;">Href</span>.<span style="color: #0000FF;">StartsWith</span><span style="color: #000000;">&#40;</span>themePath<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">ToList</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
                <span style="color: #008080; font-style: italic;">// remove the automatically added style sheets</span>
                removeCandidate.<span style="color: #0600FF;">ForEach</span><span style="color: #000000;">&#40;</span>Page.<span style="color: #0000FF;">Header</span>.<span style="color: #0000FF;">Controls</span>.<span style="color: #0000FF;">Remove</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">override</span> <span style="color: #0600FF;">void</span> AddParsedSubObject<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> obj<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #008080; font-style: italic;">// only add Style controls</span>
            <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>obj <span style="color: #008000;">is</span> Style<span style="color: #000000;">&#41;</span>
                <span style="color: #0600FF;">base</span>.<span style="color: #0000FF;">AddParsedSubObject</span><span style="color: #000000;">&#40;</span>obj<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>So what do you guys think? Is this a good solution to the asp.net theme problem? And what about the code? These two controls are my first attempt at writing custom server controls, so any input is very much welcome.</p>
<p>Get the code, <a href='http://egilhansen.com/wp-content/assimilatedwebcontrols.zip'>including Visual Studio 2008 solution and .dll</a> if you just want to use the controls.</p>
]]></content:encoded>
			<wfw:commentRss>http://egilhansen.com/2008/11/30/how-to-take-control-of-style-sheets-in-aspnet-themes-with-the-styleplaceholder-and-style-control/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>CSS trick: Always show scrollbars</title>
		<link>http://egilhansen.com/2007/03/28/css-trick-always-show-scrollbars/</link>
		<comments>http://egilhansen.com/2007/03/28/css-trick-always-show-scrollbars/#comments</comments>
		<pubDate>Wed, 28 Mar 2007 18:03:12 +0000</pubDate>
		<dc:creator>Egil Hansen</dc:creator>
				<category><![CDATA[CSS]]></category>

		<guid isPermaLink="false">http://www.egil.dk/2007/03/28/css-trick-always-show-scrollbars/</guid>
		<description><![CDATA[I worked on a site a few weeks ago where the user wanted visible scrollbars no matter how much space the content takes up on the page. Internet Explorer is happy to oblige, just put in a overflow: scroll; in your CSS and your good to go. However, Mozilla Firefox wouldn&#8217;t play ball. A bit [...]]]></description>
			<content:encoded><![CDATA[<p>I worked on a site a few weeks ago where the user wanted visible scrollbars no matter how much space the content takes up on the page. Internet Explorer is happy to oblige, just put in a <code>overflow: scroll;</code> in your <acronym title="Cascading Style Sheets">CSS</acronym> and your good to go. However, Mozilla Firefox wouldn&#8217;t play ball. A bit of Googling revealed Mozillas own implementation -<br />
<code>overflow: -moz-scrollbars-vertical;</code>.</p>
<p>So to sum up, add the following <acronym title="Cascading Style Sheets">CSS</acronym> code to your site if you want the scrollbars visible at all times:</p>
<pre><code>html {
     overflow: -moz-scrollbars-vertical;
     overflow: scroll;
}</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://egilhansen.com/2007/03/28/css-trick-always-show-scrollbars/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
	</channel>
</rss>
