print the contents of a div

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
 
P

Paul Henderson

You probably need to open the document itself for writing:

WinPrint.document.open();

before the line to write in the HTML...
 
E

Eric

thanks, but that is not the solution.

any other suggestions that can help?

rg,
Eric
 
P

Paul Henderson

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 :)
 
E

Eric

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
 
Joined
Sep 12, 2008
Messages
2
Reaction score
0
can u replace this:

<input type="button" value="Print" onclick="CallPrint('divPrint');" style="width: 110px" id="Button1" />&nbsp;<br />

instead of

<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" />
 
Joined
Sep 12, 2008
Messages
2
Reaction score
0
can u replace this:

<input type="button" value="Print" onclick="CallPrint('divPrint');" style="width: 110px" id="Button1" />&nbsp;<br />

instead of

<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" />
 
Joined
Mar 26, 2010
Messages
1
Reaction score
0
var prtContent = document.getElementById("divPrintContents");
var WinPrint = document.getElementById("ifmPrintContents").contentWindow;
WinPrint.document.open();
WinPrint.document.write(prtContent.innerHTML);
WinPrint.document.close();
WinPrint.focus();
WinPrint.print();


add an iframe to the page

<iframe id="ifmPrintContents" style="height: 0px; width: 0px; position: absolute"></iframe>
 
Joined
Oct 31, 2008
Messages
3
Reaction score
0
voila

swapnamk, excellent. working well for me. i have a print icon inside it and it is getting printed either we have to move it off the div or hide it. could you suggest any?
 

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

Members online

Forum statistics

Threads
473,995
Messages
2,570,225
Members
46,815
Latest member
treekmostly22

Latest Threads

Top