简体   繁体   English

如何在没有母版页的情况下在 asp.net 中打印页面并更改页面的配色方案?

[英]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我在 asp.net 中做了一个页面,我有一个成本计算器,它有 50 多个字段,相互依赖,一个是前两个的结果,就像这样,我希望我的页面打印得很好,并且母版页中的页面的 header 不应打印,还有我要调整的配色方案,让我知道 .net 提供的最佳解决方案

Put the content inside <div id="divid">YOUR CONTENT NEEDS TO BE PRINTED</div>将内容放入<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.然后在单击按钮时调用 javascript function 将打印所选区域或仅打印 div 的 html。 pass the id of div on calling javascript function.在调用 javascript function 时传递 div 的 id。

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');");在按钮的 onclick() 上调用 CallPrint('DivGrid');" 或在下面使用: but.Attributes.Add("OnClick", "return CallPrint('DivGrid');");

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.创建一个空的母版页 (PrintVersion.Master) 作为打印版本。 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.使 href 加载当前页面。 From the href add a querystring so you can capture it from your content page preinit event.从 href 添加一个查询字符串,以便您可以从内容页面的 preinit 事件中捕获它。
  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"从您的内容页面 preinit 事件中检测要打印的查询字符串是否存在,然后指定空白母版页,例如: MasterPageFile = "~/Ful/Path/of/your/PrintVersion.Master"
  4. Optional, on the PrintVersion.Master on document.ready call: window.print();可选,在 PrintVersion.Master 上 document.ready 调用:window.print(); The browser print dialog will automatically open.浏览器打印对话框将自动打开。

You can make a new printable page version, which doesn't include a header.您可以制作新的可打印页面版本,其中不包含 header。 This version can also have the layout you need.这个版本也可以有你需要的布局。

Nothing to do with.Net and everything to do with a print stylesheet.与.Net 无关,与打印样式表无关。 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.注意media="print"表示它将用于打印页面。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM