Click here to Skip to main content
12,944,121 members (57,567 online)
Rate this:
Please Sign up or sign in to vote.
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
function PrintDiv() {
    var divToPrint = document.getElementById("<%=Printable.ClientID%>");
    var popupWin ='', '_blank', 'width=300,height=300');;
    popupWin.document.write('<html><body  önload='window.print();'>' + divToPrint.innerHTML + </html>');
for (int i = 0; i < GridView1.Rows.Count; i++)
            CheckBox chk = (CheckBox)GridView1.Rows[i].Cells[0].FindControl("chkselect");
            if (chk.Checked)
                Page.ClientScript.RegisterStartupScript(Page.GetType(), "Script", "PrintDiv();", true);
Posted 25-Nov-12 20:15pm
Updated 25-Nov-12 22:28pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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.
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
aspnet_regiis -i 27-Nov-12 9:20am
devausha 27-Nov-12 22:38pm
How to do it? Pls reply me...this is my big problem
aspnet_regiis -i 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)

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 4,653
CHill60 2,970
Maciej Los 2,388
Jochen Arndt 1,900
ppolymorphe 1,765

Advertise | Privacy | Mobile
Web02 | 2.8.170518.1 | Last Updated 27 Nov 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100