?
Solved

Print an aspx page

Posted on 2006-05-15
9
Medium Priority
?
984 Views
Last Modified: 2012-06-27
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
Comment
Question by:NBilly
  • 4
  • 2
  • 2
  • +1
9 Comments
 
LVL 1

Assisted Solution

by:quannv
quannv earned 80 total points
ID: 16683919
<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
 
LVL 35

Assisted Solution

by:mrichmon
mrichmon earned 80 total points
ID: 16683979
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
 

Author Comment

by:NBilly
ID: 16684311
Where would I put this code?  In the code behind?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 35

Expert Comment

by:mrichmon
ID: 16684325
No in the head of the .aspx page.  It is javascript code.
0
 

Author Comment

by:NBilly
ID: 16684992
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
 
LVL 7

Accepted Solution

by:
mmarksbury earned 1840 total points
ID: 16685925
<input type="button" name="PrintButton" onclick="javascript:window.print();" value="Print Page" />
0
 

Author Comment

by:NBilly
ID: 16686214
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
 
LVL 7

Expert Comment

by:mmarksbury
ID: 16686229
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
 

Author Comment

by:NBilly
ID: 16686280
mmarkbury,

I got it working the way I want it to work.  Thank you.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…

807 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