I once had a requirement to print a portion of the page using AjaxToolkit. Below is my sample code to generate a printable simple report on button click:
<ajaxToolkit:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</ajaxToolkit:ToolkitScriptManager>
<script type="text/javascript">
function PrintPanel() {
var panel = document.getElementById("<%=Panel1.ClientID %>");
var printWindow = window.open('', '', 'height=500,width=1000');
printWindow.document.write('<html><head><title>My Sample Report</title></head>');
printWindow.document.write('<body style="font-size: 12px; font-family: Calibri">');
printWindow.document.write(panel.innerHTML);
printWindow.document.write('</body></html>');
printWindow.document.close();
setTimeout(function () {
printWindow.print();
}, 500);
return false;
}
</script>
<asp:Button ID="btnPrint" runat="server" Text="Print Report" OnClientClick="return PrintPanel();" Visible="False" />
<asp:Panel ID="Panel1" runat="server" CssClass="modalPopup" BackColor="#ffffff">
//All your HTML layout and elements, reports, GridView, etc. go here
</asp:Panel>
No comments:
Post a Comment