Click here to Skip to main content
16,016,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
sir,
i want take printout my form in asp.net, when i clicked button print(button name) it should get hardcopy of my page is it possible in asp.net
thank you
Posted
Updated 4-Nov-14 20:21pm
v2

 
Share this answer
 
Try this jscript...

XML
<script type="text/javascript">
            function printGrid() {
                var gridData = document.getElementById('<%= yourForm.yourformID %>');
                var windowUrl = 'Youraspxfilename.aspx';
                //set print document name for gridview
                var uniqueName = new Date();
                var windowName = 'Print_' + uniqueName.getTime();

                var prtWindow = window.open(windowUrl, windowName,
                'left=100,top=100,right=100,bottom=100,width=700,height=500');
                prtWindow.document.write('<html><head></head>');
                prtWindow.document.write('<body style="background:none !important">');
                prtWindow.document.write(gridData.outerHTML);
                prtWindow.document.write('</body></html>');
                prtWindow.document.close();
                prtWindow.focus();
                prtWindow.print();
                prtWindow.close();
            }
        </script>



Try this print button in Aspx file...
XML
<div class="form-group col-md-4">
            <asp:Button ID="btnPrint" runat="server" Text="Print Data" OnClientClick="printGrid()" />&nbsp;&nbsp; <asp:Button ID="btnPrintFromCodeBehind" runat="server" Text="Print From" OnClick="btnPrintFromCodeBehind_Click" Visible="false" />
        </div>




C# code...

C#
protected void btnPrintFromCodeBehind_Click(object sender, EventArgs e)
   {
       try
       {
           ScriptManager.RegisterStartupScript(this, typeof(Page), "printGrid", "printGrid();", true);
       }
       catch
       {
       }
   }
 
Share this answer
 
v3
Here you go with this code, Enjoy :
ASP.NET
<asp:Button ID="printButton" runat="server" Text="Print" OnClientClick="javascript:window.print();" />
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900