14 August 2017

How to print content of the page using ASP.NET AjaxToolkit

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">
<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">');
        setTimeout(function () {
        }, 500);
        return false;

 <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

No comments:

Post a Comment