Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1122
  • Last Modified:

ASP - print button or print image

I have an ASP page that I need to print. User can right click on the page and select 'print' and this is ok, but I want to add an icon to print the page. If simply add an image with javascript then the icon is also printed along with the ASP page.
I want to add either an image or a button that sends the ASP page to the printer but does NOT print the icon (image) or the button.

How can I do this ?
0
Aleks
Asked:
Aleks
2 Solutions
 
Scott Fell, EE MVEDeveloperCommented:
Create a css for print http://www.w3schools.com/css/css_mediatypes.aspa and set the class of the print button to not display for print.  You could create a separate page for printing but that is extra work.

@media print
  {
  .print_button {display:none}
  }

Open in new window

0
 
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
since you want an actual button or image to print the page, I would open up the page in a modal window, then in the load event of the modal dialog, you can use window.print() to open up the printer dialog window.

so on your main page, you would have something like:

<input type="button" value="Print" onclick="window.open( '/printPage.asp' );" />

and in printPage.asp, you add the following line to your onload event of the page:

window.print()

if you want everything on the same page, you could do something like this (if you don't want to go the css route Scott Suggested:

<input id="printMe"  type="button" value="Print" onclick="printPage()" />

and your function would look like:

function printPage() {
     //-- hide the button (and whatever else you don't want shown
     document.getElementById('printMe').display = 'none';

    //-- window.print();
}
0
 
AleksAuthor Commented:
Thank you. I will give this a try
0
 
GaryCommented:
I've requested that this question be closed as follows:

Accepted answer: 500 points for padas's comment #a40017934

for the following reason:

This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0
 
AleksAuthor Commented:
Sorry for the delay
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now