C# 如何在asp.net中打印没有母版页的页面并更改页面的颜色方案?

C# 如何在asp.net中打印没有母版页的页面并更改页面的颜色方案?,c#,asp.net,visual-studio,printing,C#,Asp.net,Visual Studio,Printing,我在asp.net中制作了一个页面,我有一个成本计算器,它有50多个字段,相互依赖,其中一个是前两个字段的结果,就像这样,我希望我的页面以良好的方式打印,母版页的页眉不应打印,还有我要调整的颜色方案,请告诉我.net为此提供的最佳解决方案。您可以制作一个新的可打印页面版本,其中不包括页眉。此版本还可以具有您需要的布局。与.Net无关,与打印样式表有关。您可以创建一个样式表,该样式表仅在打印页面时有效。你可以改变一切,从显示到位置再到颜色 使用: 注意media=“print”表示它将用于打印

我在asp.net中制作了一个页面,我有一个成本计算器,它有50多个字段,相互依赖,其中一个是前两个字段的结果,就像这样,我希望我的页面以良好的方式打印,母版页的页眉不应打印,还有我要调整的颜色方案,请告诉我.net为此提供的最佳解决方案。

您可以制作一个新的可打印页面版本,其中不包括页眉。此版本还可以具有您需要的布局。

与.Net无关,与打印样式表有关。您可以创建一个样式表,该样式表仅在打印页面时有效。你可以改变一切,从显示到位置再到颜色

使用:



注意
media=“print”
表示它将用于打印页面。

将内容放入
您需要打印的内容

然后单击按钮调用javascript函数,它将打印所选区域或仅打印div的html。在调用javascript函数时传递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;
}
函数调用打印(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(“”);
WinPrint.document.write(prtContent.innerHTML);
WinPrint.document.write(“”);
WinPrint.document.close();
WinPrint.focus();
print.print();
WinPrint.close();
返回false;
}

调用CallPrint('DivGrid');“在按钮的onclick()上或在下面使用:
but.Attributes.Add(“onclick”,“return CallPrint('DivGrid');”);
我知道这个问题很久以前就被问过了,但是没有被接受的建议。所以这里是我使用母版页时友好打印版本的方法

  • 创建一个空的母版页(PrintVersion.master)作为打印版本服务。如果需要打印,请在母版页中添加任何内容(如徽标)
  • 在内容页中,添加一个目标为空的打印链接。使href加载当前页面。从href添加一个查询字符串,以便可以从内容页preinit事件中捕获它
  • 从您的内容页PrimIIT事件检测是否存在打印字符串,然后指定空白母版页:Master Page Fiel= =“//FUL/PAT/OF/HY/PrrtValuo.Master”
  • 可选,在PrintVersion.Master on document.ready上调用:window.print();浏览器打印对话框将自动打开
  • 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;
    }