Reputation: 9611
I have a page from which the user will be able to print. However, the page which will get printed is not the one the user is viewing, but rather a new one I'd like to generate on the background and (possibly) only show the print dialog for it.
Just to make things clear:
FYI, what I'm trying to avoid is to have the "Printable.aspx" open in a new window and then show its print dialog.
Thanks in advance.
Upvotes: 7
Views: 4243
Reputation: 12465
Use a combination of MEDIA tags in CSS to show/hide objects for printing.
<STYLE type="text/css">
@media print {
.PrintOnly {font-size: 10pt; line-height: 120%; background: white;}
}
@media screen {
.PrintOnly {display: none}
}
</STYLE>
You can make controls that are style Display:none
on media screen, so the user only sees them when printing.
<DIV class="PrintOnly">
This control will only show up during printing
</DIV>
Any of your controls can be classed as "PrintOnly" so you only see them when printing. You just need to have the css class defined once for "@media screen" and once for "@media print" to ensure they behave differently.
You can also bring in an entire stylesheet for print-only.
<LINK rel="stylesheet" type"text/css" href="screen.css" media="screen">
<LINK rel="stylesheet" type"text/css" href="print.css" media="print">
Upvotes: 12
Reputation: 13151
When the Print button is clicked, add the Printable.aspx into a hidden panel of view.aspx. Respond by adding javascript into the onload event of view.aspx & print the hidden panel with window.print()
Upvotes: 1
Reputation: 32505
You could load the page into a hidden IFrame element, then use javascript to execute the print function of that page.
But, like @carter suggested, CSS is the better approach. Why load duplicate content more than once when you can just restyle the current content?
Upvotes: 0
Reputation: 10847
I don't think what you are trying for is possible. But I could be wrong. Though the better way to approach this is to use a different css stylesheet.
Upvotes: 0