在asp.net中打印 [英] Printing in asp .net
问题描述
嗨朋友们,
这是我页面的结构。当我点击打印按钮时,它列出了用户控制文件夹的目录。
< masterpage>
< contentpage>
< usercontrol>
br mode =hold/>
Hi Friends,
This is the structure of my page. When i click on print button, it is listing the directory of user control folder.
<masterpage>
<contentpage>
<usercontrol>
br mode="hold" />
内容........................
content........................
< contentpage>
< masterpage>
以下方法即时通话点击
<contentpage>
<masterpage>
The below method im calling on click
function CallPrint(strid) {
var print = window.confirm('Are you sure to take print out of the Page? Click OK to print. Otherwise, click Cancel.');
if (print == true) {
var prtContent = document.getElementById(strid);
var WinPrint = window.open('', '', 'left=0,top=0,toolbar=0,scrollbars=1,status=0');
var content = "<link rel='stylesheet' href='PrintStyle.css' type='text/css'/><table width=820><tr><td height=12px></td></tr><tr><td style=width:20px></td><td>" + prtContent.innerHTML + "</td></tr></table>";
WinPrint.document.write(content);
WinPrint.document.close();
WinPrint.focus();
WinPrint.print();
WinPrint.close();
return true;
}
else {
return false;
}
}
我认为内容在用户控件内,因为它是列表。这就是为什么我试图重定向到另一个页面。但它没有重定向。
请建议我哪里错了...
I think the content is within the user control because of that, it is listing. that is why i tried to redirect to another page. but it is not redirecting.
Please suggest me where im wrong...
推荐答案
您好,
我这样测试了你的代码,它对我很有用:
Hello,
I tested your code like this, and it worked well for me :
<label id="lbl">TEST TEST TEST</label>
<input type="button" onclick="CallPrint('lbl')" />
<script type="text/javascript">
function CallPrint(strid) {
var print = window.confirm('Are you sure to take print out of the Page? Click OK to print. Otherwise, click Cancel.');
if (print == true) {
var prtContent = document.getElementById(strid);
var WinPrint = window.open('', '', 'left=0,top=0,toolbar=0,scrollbars=1,status=0');
var content = "<link rel='stylesheet' href='PrintStyle.css' type='text/css'/><table width=820><tr><td height=12px></td></tr><tr><td style=width:20px></td><td>" + prtContent.innerHTML + "</td></tr></table>";
WinPrint.document.write(content);
WinPrint.document.close();
WinPrint.focus();
WinPrint.print();
WinPrint.close();
return true;
}
else {
return false;
}
}
</script>
这篇关于在asp.net中打印的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!