Muhammad Atif Agha
Muhammad Atif Agha

Reputation: 1545

How can i print a page in asp.net without master page and to change color schemes of the page?

i have made a page in asp.net, i have a costing calculator which has more than 50 fields, dependent on each other, one is the result of previous two and like that, i want my page to be printed in a well manner, and the header of the page which is in master page should not be in print, also the color schemes i want to adjust, let me know the best solution for this which .net provides

Upvotes: 2

Views: 7024

Answers (4)

Muhammad Akhtar
Muhammad Akhtar

Reputation: 52241

You can make a new printable page version, which doesn't include a header. This version can also have the layout you need.

Upvotes: 0

Mario
Mario

Reputation: 335

I know that question has been asked a long time ago, however there is no accepted suggestion. So here my approach for friendly print version when using Master page.

  1. Create an empty master page (PrintVersion.Master) to serv as print version. Add what ever you need to be print (like logos) if anything to that master page.
  2. from your content page, add a print link with target blank. Make the href to load the current page. From the href add a querystring so you can capture it from your content page preinit event.
  3. From your content page preinit event detect if the querystring to print exists, then specify the blank master page like: MasterPageFile = "~/Ful/Path/of/your/PrintVersion.Master"
  4. Optional, on the PrintVersion.Master on document.ready call: window.print(); The browser print dialog will automatically open.

Upvotes: 0

Saurabh
Saurabh

Reputation: 5727

Put the content inside <div id="divid">YOUR CONTENT NEEDS TO BE PRINTED</div>

Then call the javascript function on button click which will print the selected area or only html of div. pass the id of div on calling javascript function.

function CallPrint(var strid)
{

var prtContent = document.getElementById(strid);
var WinPrint = window.open('','','letf=10,top=10,width="450",height="250",toolbar=1,scrollbars=1,status=0');

WinPrint.document.write("<html><head><LINK rel=\"stylesheet\" type\"text/css\" href=\"css/print.css\" media=\"print\"><LINK rel=\"stylesheet\" type\"text/css\" href=\"css/print.css\" media=\"screen\"></head><body>");

WinPrint.document.write(prtContent.innerHTML);
WinPrint.document.write("</body></html>");
WinPrint.document.close();
WinPrint.focus();
WinPrint.print();
WinPrint.close();

return false;
}

Call CallPrint('DivGrid');" on onclick() of button or use below: but.Attributes.Add("OnClick", "return CallPrint('DivGrid');");

Upvotes: 4

anothershrubery
anothershrubery

Reputation: 20993

Nothing to do with .Net and everything to do with a print stylesheet. You can create a stylesheet which will only work for when the page is printed. And you can change everything from what displays to postion to colours.

Use:

<LINK rel="stylesheet" type"text/css" href="print.css" media="print">

Note media="print" means it'll be used for printed pages.

Upvotes: 0

Related Questions