Link to home
Start Free TrialLog in
Avatar of Angela4eva
Angela4eva

asked on

print gridview example

I am using this code
http://archive.aspsnippets.com/demos/gridviewprint.aspx
to print a gridview. All works fine except with the page in the background it shows a popup to select the printer.I do not want to show that popup can anyone help me with it.
thanks
ASKER CERTIFIED SOLUTION
Avatar of third
third
Flag of Philippines image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
A user CurtisDeHaven posted a solution to this problem at the following link:

http://social.msdn.microsoft.com/Forums/en/iewebdevelopment/thread/86eaeda9-c868-4d20-95b8-3b9bc2e19cc6

It will only work for Internet Explorer.  It has been confirmed as working in IE7 and IE8, but only after the  "Enable scripting of the WebBrowser" setting is enabled, which is non-default and could be a security risk.

So this might be an option if you are page is running in an Intranet scenario and your company has standardised on IE.
Avatar of Angela4eva
Angela4eva

ASKER

"this is not possible. every browser prompts for the print dialog before you do the actual printing. this is actually good. imagine if browsers don't prompt with print dialog, there will be sites that will waste your inks in your printer. "
I do not think you understood i do not want to print automatically. I want to show the print page but not the dialogue box. There is print icon on the top of the grid page to print it
if that is the case, then don't call window.print() automatically. check your source code. it's probably called on the window.onload event. instead, just call it on the onclick event of your print icon.
Asker did not reply to expert's comments (#35196540 and #35203640).  If the asker still wants a solution, I am sure we will be happy to help them achieve a solution.
Asker did not reply to expert's comments (#35196540 and #35203640).  If the asker still wants a solution, I am sure we will be happy to help them achieve a solution.
"It will only work for Internet Explorer.  It has been confirmed as working in IE7 and IE8, but only after the  "Enable scripting of the WebBrowser" setting is enabled, which is non-default and could be a security risk."
Cannot ask every users to change their IE settings.

third,
what do you mean
Please delete the question
Hi

Can you tell us who the users of your web site are?  Are they all staff in your company, using your network?  If so, rather than have to ask every user to change their IE settings, you can use group policy to change their security settings centrally.

There is a very useful article here: http://javascript.about.com/od/events/a/print.htm that describes why JavaScript does not have the ability to print without displaying the dialog box.  It explains that an intranet is the only scenario where it might be possible (as I stated in my previous answer).

Other users say that this approach works in Firefox: http://fiddyp.co.uk/bypass-disable-print-dialog-box-in-firefox-with-javascript-print/

I have identified a company that sells a component ($1000) that enables printing without a dialog box in IE5, 6, 7, 8 and 9: http://www.meadroid.com/scriptx/samples/Licensed/advanced/release/DOCTYPE/IE7 (click "Print the page")  It also enables you to configure the printing to a much greater degree than you would usually be able to.  See http://www.meadroid.com/scriptx/index.asp for product info.


What is boils down to is that if your site is on the Internet, then what you ask is not possible - in which case you should accept the answer that first said "this is not possible".  If it is an Intranet and you use Internet Explorer, then please consider my suggestion to configure everyone's IE settings using Group Policy.  If all your users have Firefox, please try the link above.
Its Intranet. But we have 100's of web sites . I do not think network will change the group policy just for my sake.
Since I work for govt , installing a component from third part is not easy.
Even if the website is on internet I think it is possible. Just because someone said so, I do not think I will agree with them.
You didn't answer the question about which browser is in use.  If you can tell us that, it would help narrow down research.

You say you think what you are asking is possible but you don't know how.  Have you seen a web site which has this feature?  If not, what makes you think it is possible?
You didn't answer the question about which browser is in use.  If you can tell us that, it would help narrow down research.
IE8

You say you think what you are asking is possible but you don't know how.  Have you seen a web site which has this feature?  If not, what makes you think it is possible?
I think it possible because it makes sense to me. Yes, but I do not know how.

Anyways Mine web site is an intranet and I think you asking me to change my entire network group policy so your answer can work is pretty ridiculous.
Ok... now we're getting somewhere.  The following code will work for Internet Explorer 8. However, because it uses an embedded ActiveX control (the Internet Explorer ActiveX control) you WILL need to make the following change:

User generated image
You'll just have to weigh up the benefit of "silent printing" against having to pester your network admins to make the security setting change for the Intranet Zone via group policy.  By making the change only for the Intranet zone, it will only impact sites that IE detects as being on the intranet (e.g. accessed by machine name rather than DNS address) or that are explicitly added to the Intranet zone (again achievable via Group Policy)

If you still think there is a way to do what you ask without changing any security settings, then... good luck!

I hope this helps!
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <input id="printbutton" type="button" value="Print" onclick="PrintMe();" />
    </div>
    </form>
</body>
</html>
<script type="text/javascript">
function PrintMe()
{
if (navigator.appName == "Microsoft Internet Explorer")
{ 
     var PrintCommand = '<object ID="PrintCommandObject" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></object>';
     document.body.insertAdjacentHTML('beforeEnd', PrintCommand); 
     PrintCommandObject.ExecWB(6, 2); PrintCommandObject.outerHTML = ""; 
} 
else { 
window.print();
}
}
</script>

Open in new window

As I told you already I cannot get the network to change group policy just for my sake. Its not an option.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial