?
Solved

ASP.net Master page - print content only

Posted on 2007-12-06
7
Medium Priority
?
5,420 Views
Last Modified: 2010-04-21
Hi
My ASP.net master page has three content panes, imaginably called content1, content2, content3
User wants a "Print" button, so I added
                <a href="JavaScript:window.print();">Print this page</a>
This prints the whole pages, whereas I'd like it to only print the content3 area (other areas are menus, logo)
Help please. I would rather not have to have a "printer friendly" version with another copy of page.
Thanks
0
Comment
Question by:rwallacej
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
7 Comments
 
LVL 12

Expert Comment

by:Sinoj Sebastian
ID: 20420450
You have to make separate CSS for print and screen

<style type="text/css" media="print">
// CSS for printing
// hide your menu and all here
</style>

<style type="text/css" media="screen">
// CSS for Browser
// use you usual CSS here
</style>
0
 

Author Comment

by:rwallacej
ID: 20420644
can you elaborate a bit please?  say this is the "master page" and I want to print ContentPlaceHolder2
<%@ Master Language="VB" CodeFile="MasterPage.master.vb" Inherits="MasterPage" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
    <asp:ContentPlaceHolder ID="head" runat="server">
    </asp:ContentPlaceHolder>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        This is the links here
    </div>
    <div>
        <asp:ContentPlaceHolder ID="ContentPlaceHolder2" runat="server">
        ...this is what I want to print...
        </asp:ContentPlaceHolder>
    </div>
    </form>
</body>
</html>

Open in new window

0
 
LVL 12

Accepted Solution

by:
Sinoj Sebastian earned 2000 total points
ID: 20421253
give an Id to the first div
    <div id="links">
        This is the links here
    </div>
Now you need to remove this div from printout. right?

<style type="text/css" media="print">
   #links { display:none }
</style>

Now print the page from your browser
<%@ Master Language="VB" CodeFile="MasterPage.master.vb" Inherits="MasterPage" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
    <style type="text/css" media="print">
       #links { display:none }
    </style>
    <asp:ContentPlaceHolder ID="head" runat="server">
    </asp:ContentPlaceHolder>
</head>
<body>
    <form id="form1" runat="server">
    <div id="links">
        This is the links here
    </div>
    <div>
        <asp:ContentPlaceHolder ID="ContentPlaceHolder2" runat="server">
        ...this is what I want to print...
        </asp:ContentPlaceHolder>
    </div>
    </form>
</body>
</html>

Open in new window

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!

 

Author Comment

by:rwallacej
ID: 20443150
HI,
your example works great. Thank-you.
My problem is now that when I put it onto the "real" page, my left panel does not appear in view mode !
any ideas?
thanks
0
 

Author Comment

by:rwallacej
ID: 20443165
this may be as the "real" page uses an external stylesheet, I see the "media" section in your style - how do I apply this to external css?
0
 

Author Comment

by:rwallacej
ID: 20443205
tis OK, I'm sorted
0
 

Author Closing Comment

by:rwallacej
ID: 31413173
great solution
0

Featured Post

Percona Live Europe 2017 | Sep 25 - 27, 2017

The Percona Live Open Source Database Conference Europe 2017 is the premier event for the diverse and active European open source database community, as well as businesses that develop and use open source database software.

Question has a verified solution.

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

      Install BugTracker on Windows 2008 server Step 1:  Install windows 2008 server 32 bit OS and configure IIS. Step 2:  Install SQL server ( SQL server 2005 or SQL server 2005 Express edition. The installer for 2008  version isn’t very f…
A publishing tool, a Version Control System, or a Collaboration Platform! These can be some of the defining words for the two very famous web-hosting Git repositories: Bitbucket and Github. Git is widely used amongst the programmers and developers f…
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to choose which pages of your form are visible to your users based on their inputs. The page rules feature provides you with an opportunity to create if:then statements for y…
Learn how to set-up custom confirmation messages to users who complete your Wufoo form. Include inputs from fields in your form, webpage redirects, and more with Wufoo’s confirmation options.

770 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