Click here to Skip to main content
15,892,537 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a two problem for printing I am writing javascript function for print div.
In my div I am creating payslip for employee. So I assign the values that div for every employee and print. So I call javascript function in loop. But the print window is open when the loop is finished.
And another problem is I want to print div automatically with default printer, without opening dialogue box how to do it? using javascript. help me...
Thank u.....My javascript function is
JavaScript
function PrintDiv() {
    var divToPrint = document.getElementById("<%=Printable.ClientID%>");
    var popupWin = window.open('', '_blank', 'width=300,height=300');
    popupWin.document.open();
    popupWin.document.write('<html><body  önload='window.print();'>' + divToPrint.innerHTML + </html>');
            popupWin.document.close();
}

for (int i = 0; i < GridView1.Rows.Count; i++)
        {
            CheckBox chk = (CheckBox)GridView1.Rows[i].Cells[0].FindControl("chkselect");
            if (chk.Checked)
            {

                Salaryproccess();
                Page.ClientScript.RegisterStartupScript(Page.GetType(), "Script", "PrintDiv();", true);
            }
        }
Posted
Updated 25-Nov-12 22:28pm
v4

1 solution

As a developer, AND a user, I personally HATE this behavior (skipping the print dialog).

This is my #1 annoyance with MS Word, thank goodness most applications didn't follow suit.

I typically have access to at least 4, if not more printers... plus the ability to print to a file, or a PDF.

If I don't get the opportunity to pick: (a) what printer, (b) what paper size, (c) what orientation, (d) what scale, (e) color vs. black & white, and (f) what print quality, I get very upset.

These are user options and preferences. Unless you have a very good reason to avoid uses choosing these options, please do not remove the users choice.

Edit: 27 Nov 2012

Basically the print dialog is a security feature built into the web browsers.

Imagine a scenario where you visit a Domino's website to order pizzas and without clicking anything on the page , your printer begins printing the pizza menus on the printer attached to your machine until the printer runs out of paper. Will you be happy with it?

So the browser does not allow to print unless the user approves the print action. Since this is a browser feature , you cannot override it.

The workaround for your scenario mentioned in your comment below is to generate a 100 page pdf for printing 100 pages at a time.
 
Share this answer
 
v2
Comments
devausha 26-Nov-12 23:16pm    
ok, you're correct. But In my case I get payslip for employees. So I select all the employees name and get the payslip for all the employee. So every time the user can't select printer option for 100 employees.
devausha 27-Nov-12 3:59am    
Ok I m creating div with table at design time, that div contains labelbox and textboxes. Is it possible same div with table 100 times for every employee at runtime
bbirajdar 27-Nov-12 9:20am    
Yes.
devausha 27-Nov-12 22:38pm    
How to do it? Pls reply me...this is my big problem
bbirajdar 28-Nov-12 1:17am    
I can't unless you show me how you are generating the PDF...

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