Click to See Complete Forum and Search --> : How can I print a web page ?


Robert Chu
10-13-2006, 05:40 AM
Hello,
I use the following code to print a page. But there is an error message:
'javascript' is not a member of 'ASP.printTest_aspx'. What's wrong with the code ? Thanks.



<html><head>
<script language=javascript>
function CallPrint(strid)
{
var prtContent = document.getElementById(strid);
var WinPrint = window.open('','','letf=0,top=0,width=1,height=1,toolbar=0,scrollbars=0,status=0');
WinPrint.document.write(prtContent.innerHTML);
WinPrint.document.close();
WinPrint.focus();
WinPrint.print();
WinPrint.close();
prtContent.innerHTML=strOldOne;
}
</script>
</head>
<body>
<div id="divPrint">
test
</div>
<asp:button ID="btnPrint" onClick="javascript:CallPrint('divPrint');" Runat=Server />
</body>

felgall
10-13-2006, 07:09 AM
Try changing:

onClick="javascript:CallPrint('divPrint');"

to:

onClick="CallPrint('divPrint');"

the onclick already knows it is Javascript and that label is confusing the ASP.

Robert Chu
10-15-2006, 11:38 PM
Hello,
I tried both your ways and the following codes. But it still has some error messages:
'onClientClick' is not a member of 'System.Web.UI.WebControls.Button'. How can I fix it ?


<html><head>
<script language=javascript>
function CallPrint(strid)
{
var prtContent = document.getElementById(strid);
var WinPrint = window.open('','','letf=0,top=0,width=1,height=1,toolbar=0,scrollbars=0,status=0');
WinPrint.document.write(prtContent.innerHTML);
WinPrint.document.close();
WinPrint.focus();
WinPrint.print();
WinPrint.close();
prtContent.innerHTML=strOldOne;
}
</script>
</head>
<body>
<div id="divPrint">
test
<form runat = "server">
<asp:button ID="btnPrint" text = "列印" Runat="Server"/>


</form>
</div>
<% btnPrint.onClientClick = "JavaScript:CallPrint('divPrint');" %>
</body>
</html>

sirpelidor
10-16-2006, 02:55 PM
<% btnPrint.onClientClick = "JavaScript:CallPrint('divPrint');" %>


use html instead,

<input type="button" onclick="CallPrint('divPrint')" />