Printing multiple pages on Button Click in ASP.net
In our web application we have multiple web pages. Contacts module is One of the widely used module. The entire module consists of 3 pages.
The First page displays the Contact details with several Server controls, the开发者_Go百科 second page is contact history with all the history about the contact and 3rd page again some more details of the contact.
Is there any way when a user hits one button on any of these pages, it prints all the 3 pages. With the content for this contact. Please note these are not static pages. The contact details are displayed based on the data in our Oracle DB.
If all of those pages are generated dynamically, what you need to do is to create a 4-th page that generates all 3 of those pages combined and then include a URL to that page on each of 3 pages you have as follows:
<link rel=alternate media=print href="urlToCombinePage">
This will instruct a browser to use your 4-th page any time somebody wants to print one of 3 pages that you already have. Substitution should happen automatically, and shouldn't be noticeable for the user, until they get their printed document.
Only other way that I can think of is to re-write all three of your pages and combine them into one, then you can use Javascript to show and hide part of the page, and you can use @media=print css stylesheet to show all of them when the document is being printed.
Ideally, you convert pages into user controls then add a new page containing all the new controls.
Another way I've done this when up against a deadline to avoid having to rewrite a collection of pages into user controls is to use a separate page that I open in a new window.
This is passed the urls of the pages to display via parameters (or by session - your choice).
Process is then:
foreach(var page in pages)
Server.Execute(page, Response.Output);
// Inject a window.print() command via a script block
It's a bit hack-y as you're parsing multiple complete pages which is obviously invalid HTML, but if you've got standardised stylesheets, suitable print media styles and your pages aren't extremely complex, you'll get away with it.
If you want to be more thorough, process each page in turn, concatenating the bodies so you have a single page.
精彩评论