Print CSS in ASP.Net Theme

Monday, August 10, 2009

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.

1 comment(s) for “Print CSS in ASP.Net Theme”

  1. Gravatar of silversrt
    silversrt Says:
    I didn't understand the concluding part of your article, could you please explain it more?

Leave comment:

Name:  
Email:  
Website:
Comment: