Force additional CSS file after the generated link tags from a APP_Themes folder

Jul 9, 2007 at 12:45 PM
I ran into another interesting challenge inplementing the CSSFriendly Adapter. It goes like this:

I use CSS files in the themes folder as it makes usability sense (and because I prefer CSS vs .skin files, although I have both).

However, to include additional optional CSS becomes interesting. Inserting them via a literal control, is, of course no challenge, But forcing them below the generated CSS links seems to elude me.

Note that it is not the sequencing of the CSS files. This can be controlled by simply naming them in the sort sequence one desires and ASP.NET will create the link elements in the same sequence.

The problem is to force, for example, the following under the generated CSS files:

<!--[if lt IE 7]>
<link rel="stylesheet" href="clientlibs/MenuIE6.css" type="text/css" />
<link rel="stylesheet" href="clientlibs/blue_site$MenuIE6.css" type="text/css" />
<![endif]-->
Jul 9, 2007 at 4:56 PM
If you add the link during OnPreRender it will come after the Theme stylsheets.

protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);

HtmlLink link = new HtmlLink();
link.Attributes.Add("type", "text/css");
link.Attributes.Add("rel", "stylesheet");
link.Attributes.Add("href", "~/newstyle.css");
Page.Header.Controls.Add(link);
}
Jul 9, 2007 at 8:39 PM

LonelyRollingStar wrote:
If you add the link during OnPreRender it will come after the Theme stylsheets.

protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);

HtmlLink link = new HtmlLink();
link.Attributes.Add("type", "text/css");
link.Attributes.Add("rel", "stylesheet");
link.Attributes.Add("href", "~/newstyle.css");
Page.Header.Controls.Add(link);
}


Thank you. I will try it.

Scanning the code it would appear that the previous header controls are ready to be rendered and one is simply adding a control to this just prior to .NET rendering the output.

Thanks again. I will let you know...