Solved

ASP.net Master page - print content only

Posted on 2007-12-06
7
5,215 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Using Quotation Marks in PHP This question (http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_28217211.html) seems to come up a lot for developers who are new to PHP.  And it got me thinking, "How can we explain the rule…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video teaches users how to migrate an existing Wordpress website to a new domain.
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.

762 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

22 Experts available now in Live!

Get 1:1 Help Now