Solved

print gridview example

Posted on 2011-03-22
17
613 Views
Last Modified: 2012-05-11
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
0
Comment
Question by:Angela4eva
  • 7
  • 7
  • 2
17 Comments
 
LVL 30

Accepted Solution

by:
third earned 300 total points
Comment Utility
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.
0
 
LVL 12

Expert Comment

by:Hairbrush
Comment Utility
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.
0
 

Author Comment

by:Angela4eva
Comment Utility
"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
0
 
LVL 30

Expert Comment

by:third
Comment Utility
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.
0
 
LVL 12

Expert Comment

by:Hairbrush
Comment Utility
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.
0
 
LVL 12

Expert Comment

by:Hairbrush
Comment Utility
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.
0
 

Author Comment

by:Angela4eva
Comment Utility
"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.

0
 

Author Comment

by:Angela4eva
Comment Utility
third,
what do you mean
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

Author Comment

by:Angela4eva
Comment Utility
Please delete the question
0
 
LVL 12

Expert Comment

by:Hairbrush
Comment Utility
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.
0
 

Author Comment

by:Angela4eva
Comment Utility
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.
0
 
LVL 12

Expert Comment

by:Hairbrush
Comment Utility
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?
0
 

Author Comment

by:Angela4eva
Comment Utility
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.
0
 
LVL 12

Expert Comment

by:Hairbrush
Comment Utility
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:

You must change this setting (or ask your network admin to set it via group policy)
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

0
 

Author Comment

by:Angela4eva
Comment Utility
As I told you already I cannot get the network to change group policy just for my sake. Its not an option.
0
 
LVL 12

Assisted Solution

by:Hairbrush
Hairbrush earned 200 total points
Comment Utility
Ok.  So in conclusion:

There is no way to suppress display of the print dialog in Internet Explorer 8 apart from using an embedded IE ActiveX control together with an IE security settings change to allow scripting of ActiveX controls not marked as safe.

I am sorry if that is a disappointment and not the answer you were hoping for.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now