Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#Javascript
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 = 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 25-Nov-12 20:15pm
devausha1.4K
Edited 25-Nov-12 22:28pm
v4

1 solution

Rate this: bad
good
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.
  Permalink  
v2
Comments
devausha at 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 at 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 at 27-Nov-12 9:20am
   
Yes.
devausha at 27-Nov-12 22:38pm
   
How to do it? Pls reply me...this is my big problem
aspnet_regiis -i at 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
Your Filters
Interested
Ignored
     
0 Shai Vashdi 1,518
1 OriginalGriff 503
2 Manas Bhardwaj 393
3 Tadit Dash 310
4 Damith Weerasinghe 290
0 Sergey Alexandrovich Kryukov 9,575
1 OriginalGriff 5,856
2 Peter Leow 4,405
3 Maciej Los 3,540
4 Abhinav S 3,513


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