Question

I Wanted to print a div from html(aspx) page. I have taken help from stackoverflow from an answer of related question how to print part of rendered html page in javascript

but when I am clicking on the print link nothing is happening, can anyone tell me what have I done wrong here? and what I am suppose to do to make it workable?

my aspx page is like

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
 <title>Report for Form Sale Money recipt</title>
<link href="../CSS/Report/myprintstyle.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
    printDivCSS = new String ('<link href="../CSS/Report/myprintstyle.css" rel="stylesheet" type="text/css">')
    function printDiv(ReportDiv) {
        window.frames["print_frame"].document.body.innerHTML=printDivCSS + document.getElementById(divId).innerHTML
        window.frames["print_frame"].window.focus()
        window.frames["print_frame"].window.print()
    }
</script>

</head>
<body>
<form id="form1" runat="server">
<div id ="ReportDiv">
    <b>Report Div</b> <a href='javascript:printDiv('ReportDiv')'>Print</a><br/>

    <label>Money Receipt Number</label> <asp:Label runat = "server" ID = "lblMRN"></asp:Label><br />
    <label>Reference</label> <asp:Label runat = "server" ID = "lblReference"></asp:Label><br />
    <label>Form Serial</label> <asp:Label runat = "server" ID = "lblFormSL"></asp:Label><br />
    <label>Name</label> <asp:Label runat = "server" ID = "lblName"></asp:Label><br />
    <label>Program</label> <asp:Label runat = "server" ID = "lblProgram"></asp:Label><br />
    <label>Semester</label> <asp:Label runat = "server" ID = "lblSemester"></asp:Label><br />
    <label>Paid Amount</label> <asp:Label runat = "server" ID = "lblPaidAmount"></asp:Label><br />
    <label>Comments</label> <asp:Label runat = "server" ID = "lblComments"></asp:Label><br />
    <label>Bank</label> <asp:Label runat = "server" ID = "lblBank"></asp:Label>
 </div>
 <iframe name='print_frame' width='0' height='0' frameborder='0' src='about:blank'></iframe>

</form>
</body>
</html>

When I click print, I find page error at the bottom of the browser.

No correct solution

OTHER TIPS

Try this:

window.frames["print_frame"].focus();
window.frames["print_frame"].print();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top