Solved

ASP.net Master page - print content only

Posted on 2007-12-06
7
5,249 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
  • 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 500 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
JavaScript error 1 53
Calling stored proc in EDMX 11 24
Achieve json result 2 65
free scanner TWAIN can be operated with a Web application 9 41
Developer tools in browsers have been around for a while, yet they are still heavily underused by developers. Developers still fix html or CSS then refresh page to see effect, or they put alert or debugger in JavaScript and then try again and again …
Introduction A frequently used term in Object-Oriented design is "SOLID" which is a mnemonic acronym that covers five principles of OO design.  These principles do not stand alone; there is interplay among them.  And they are not laws, merely princ…
Wufoo.com provides powerful tools for surveying targeted groups, and utilizing data from completed surveys to find trends, discover areas of demand or customer expectation, and make business decisions on products or services.
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to selectively show certain fields based on user input using rules to gather relevant information and data from your forms. The rules feature provides you with an opportunity…

867 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now