Print CSS in ASP.Net Theme

Most of my professional career I have worked with Microsoft products and for companies that use Microsoft solutions. But often the way that things are handled by them is not always "standard".

Take the Masterpage and Theme concept. It is a huge time saver and 99% of the time it works for everything. But they didn't think about the order of multible CSS files inside the Theme folder and how that would change your cascading effect if you were not carefull. You basically have to name them in alphabetical order of how you want them to be ordered. Which I guess is an easy enough work around.

But it doesn't seem to me that them took any consideration for using different media types (screen and print). At least I haven't found a nice eloquent way of doing it. So I had to figure out a work around and it wasn't to bad.

Instead of doing this in the <head> tags:

<link rel="stylesheet" type="text/css" media="screen" href="style.css" />
<link rel="stylesheet" type="text/css" media="print" href="print.css" />

I created two CSS files in the Theme folder:

style.css
print.css


Inside the style.css file I enclosed everything inside of:

@media screen
{
}

Then inside the print.css I did the same like this:

@media print
{
}

That is really all there is to it. Now you can do your standard print CSS file.

I've created a sample Visual Studio 2008 solution so you can see it in action.

Download this file and unzip it. Then open in Visual Studio and run it. You will see a simple one page web site. Then in your browser go to a print preview to see the print.css in action.

Posted on Aug10, 2009 in css,ASP.Net | 2 comments

Welcome

Life always seems to be crazy busy. But if you plan to be heard, you have to actually say something in a forum that will be noticed.

This blog is my (third) attempt to communicate to the public. I may not have a daily post. But I will certainly post regularly and have information that is useful for others.

Posted on Aug10, 2009 in | Leave comment