Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

ASP.net Master page - print content only

Posted on 2007-12-06
7
Medium Priority
?
5,456 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
Understanding Web Applications

Without even knowing it, most of us are using web applications on a daily basis. Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We often confuse these web applications tools for websites.  So, what is the difference?

 

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

Plesk WordPress Toolkit

Plesk's WordPress Toolkit allows server administrators, resellers and customers to manage their WordPress instances, enabling a variety of development workflows for WordPress admins of all skill levels, from beginners to pros.

See why 2/3 of Plesk servers use it.

Question has a verified solution.

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

What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
These days, all we hear about hacktivists took down so and so websites and retrieved thousands of user’s data. One of the techniques to get unauthorized access to database is by performing SQL injection. This article is quite lengthy which gives bas…
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…
Learn how to set-up PayPal payment integration in your Wufoo form. Allow your users to remit payment through PayPal upon completion of your online form. This is helpful for collecting membership payments, customer payments, donations, and more.

636 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