Friday, November 14, 2008 5:00 PM
I answered a post the other day about an easy way to have printer friendly look of pages in your web application and I decided to blog it here. You just need 5 minutes to have all your pages in your web application printer ready, ok maybe a bit more, like 10 minutes :)
When you design your web application, have your pages implement a master page, let us call it MainMaster.Master. Create another master page, call it PrinterFriendlyMaster.Master and make sure it has the same content holders as your MainMaster.Master, however make it printer friendly, without a header, maybe simpler footer, no background color, maybe different CSS files, etc... anything you need to do to have it ready for printers. Create a base class for all your pages, let us call it BasePage, it is a simple class like this:
public class BasePage : System.Web.UI.Page
protected void Page_PreInit(object sender, EventArgs e)
if (Request["print"] != null)
Page.MasterPageFile = "~/PrinterFriendlyPage.master";
Have all your pages derive from BasePage class.
Now at runtime, when you add a query string to a URL with print=1 the Page_PreInit of BasePage will detect that and will switch the master page dynamically to the printer friendly one, simple, modular and fast to implement.