Click here to Skip to main content
15,922,166 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,
I am making the reports in asp.net
I use one page for reports design
When Click the print option then don't go to design page directly show the print option page

my code is on print Click button is
C#
Session["Memo_No"] = txt_Memo_no.Text;
            ScriptManager.RegisterStartupScript(this, typeof(string), "OPEN_WINDOW", "var Mleft = (screen.width/2)-(900/2);var Mtop = (screen.height/2)-(500/2);window.open( 'Memo_Print.aspx', null, 'height=500,width=900,status=yes,toolbar=no,scrollbars=yes,menubar=no,location=no,top=\'+Mtop+\', left=\'+Mleft+\'' );", true);



and I Call the javascript for print option is on page load event is

C#
string printScript = @"function PrintGridView()
            {
                var gridInsideDiv = document.getElementById('grd_div');
                /*var printWindow = window.open('gview.htm','PrintWindow','letf=0,top=0,width=800,height=600,toolbar=1,scrollbars=1,status=1');*/
                var printWindow = window.open();
                printWindow.document.write(gridInsideDiv.innerHTML);
                printWindow.document.close();
                printWindow.focus();
                printWindow.print();
                printWindow.close();
            }";
            this.ClientScript.RegisterStartupScript(Page.GetType(), "PrintGridView", printScript.ToString(), true);
            btn_print.Attributes.Add("onclick", "PrintGridView();");


Please Help Me
Thanks in advance
Posted
v2

If you don't want it to do PostBack then why use an ASP.NET button?
you can use any html tag from image to button according to your needs.

Then you can add onClick JS and you get what you wanted, you can call PrintGridView();
and\or other methods if you like.

Cheers,
Edo
 
Share this answer
 
Place this javascript on the Memo_print.aspx page

JavaScript
window.onload=function PrintGridView()
            {
                var gridInsideDiv = document.getElementById('grd_div');
                /*var printWindow = window.open('gview.htm','PrintWindow','letf=0,top=0,width=800,height=600,toolbar=1,scrollbars=1,status=1');*/
                var printWindow = window.open();
                printWindow.document.write(gridInsideDiv.innerHTML);
                printWindow.document.close();
                printWindow.focus();
                printWindow.print();
                printWindow.close();
            }
 
Share this answer
 

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