• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 987
  • Last Modified:

Print an aspx page

I created aspnet aspx page that displays information. I want to put a button on the page to print the content of the aspx page. What coding do I need to do this.
0
NBilly
Asked:
NBilly
  • 4
  • 2
  • 2
  • +1
3 Solutions
 
quannvCommented:
<script language="Javascript1.2">
var message = "Print this Page";
function printpage() {
window.print();  
}
document.write("<form><input type=button "
+"value=\""+message+"\" onClick=\"printpage()\"></form>");
</script>

Hope this help

0
 
mrichmonCommented:
Realize that what the above code is doing is using Javascript to call the print function of the browser.  It is the same as the user pressing the actual print button on the browser as pressing the button it creates.

If this is not what you want, then explain a bit more what you are looking for.
0
 
NBillyAuthor Commented:
Where would I put this code?  In the code behind?
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
mrichmonCommented:
No in the head of the .aspx page.  It is javascript code.
0
 
NBillyAuthor Commented:
Do I create a button control on the aspx page.  I want to put a button control on aspx page and when I click on that button have it print the content of the page.

Also, is the <form> and </form> in code my aspx file name.
0
 
mmarksburyCommented:
<input type="button" name="PrintButton" onclick="javascript:window.print();" value="Print Page" />
0
 
NBillyAuthor Commented:
mmarksbury,

Your suggestion works.  Now I just want to position that "Pring Page" button in certain place on the aspx page.  How do I do that?
0
 
mmarksburyCommented:
Wherever you put the <INPUT> tag, it should display there.

If you want to add padding, or align it, put it inside of a div and add CSS styling.

For example...

TO ALIGN IT RIGHT:
<div id="ButtonDiv" style="text-align: right;">
  <input type="button" name="PrintButton" onclick="javascript:window.print();" value="Print Page" />
</div>

TO ALIGN IT CENTER:
<div id="ButtonDiv" style="text-align: center;">
  <input type="button" name="PrintButton" onclick="javascript:window.print();" value="Print Page" />
</div>

TO ADD PADDING:
<div id="ButtonDiv" style="padding: 12px;">
  <input type="button" name="PrintButton" onclick="javascript:window.print();" value="Print Page" />
</div>

Once it is inside the div, you can position it and stylize as needed.
0
 
NBillyAuthor Commented:
mmarkbury,

I got it working the way I want it to work.  Thank you.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

  • 4
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now