print the contents of a div

  • Thread starter Thread starter Eric
  • Start date Start date
E

Eric

I have the following code on my ASPX (ASP 2.0) page:

<head runat="server">
<meta content="text/VBScript" http-equiv="content-script-type" />
<title>Call duty</title>
<script language=javascript>
function CallPrint(strid)
{
var prtContent = document.getElementById(strid);
var WinPrint =
window.open('','','left=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>

and between the form tags:

<asp:Button ID="btPrint" runat="server" Style="left: 1508px; position:
absolute; top: 92px" Text="Click this button to print the form!"
OnClientClick="javascript:callprint('divprint')" Visible="False" />
<div id="divPrint" runat="server" style="left: 1500px; width: 715px;
position: absolute; top: 128px; height: 1200px" visible="false">
<asp:Image ID="imPrint" runat="server" Height="100%" Width="100%"
style="left: 12px; top: 4px" /></div>


The idea is that when the user clicks on the button, the contents of the DIV
is printed, nut it doesn't work.
What am I doing wrong?

Please help!

rg,
Eric
 
You probably need to open the document itself for writing:

WinPrint.document.open();

before the line to write in the HTML...
 
thanks, but that is not the solution.

any other suggestions that can help?

rg,
Eric
 
any other suggestions that can help?

It works for me if:
a) I add the line mentioned above
b) I change "javascript:callprint('divprint')" to
"javascript:CallPrint('divPrint')"
c) I make the button visible :-)
 
Thanks again, now I know what the problem was.
I didn't know it was all case-sensitive (line b)

now it works.

rg,
Eric
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top