Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Master pages and Java Script problem

Posted on 2007-11-21
9
Medium Priority
?
881 Views
Last Modified: 2013-11-07
Hi all,

I have a page that inherits from a master page and what i would like it ot do is that when the page loads i would like the print dialouge to open so that the page can be printed.

The page can not be taken out of a master page and the client is lazy and does not want to just press the print button on the browser. Therefore they require the dialouge to pop up so they can print from that.

any help would be much appreciated.

Many thanks

Cragly
0
Comment
Question by:Cragly
  • 4
  • 2
9 Comments
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 20330129
Cragly,

In the page's body tag make the following change ...

<body onload="window.print();">

Let me know if you have any questions or need more information.

b0lsc0tt
0
 

Author Comment

by:Cragly
ID: 20330568
Hi b0lsc0tt,

Thanks for the reply but the page I need to print inherits from a master page so does not have have a body tag of its own. The body tag resides in the master page and I do not want to put this peice of code in the master page as all pages within the site that use the master page will print.

Cheers

Cragly
0
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 20330952
One other way to do it is with something like ...

window.onload = function () { window.print(); }

However if by master page, etc you mean you use frames or something like it then this probably won't work either.  The frame/pages may not be all loaded.  In that case the last thing to try is a timeout.

var t = setTimeOut("window.print()", 1000);

The second argument is the time in milliseconds so the line above will wait 1 second.  Adjust as needed for your site and pages.

Let me know if you have a question or how it works.

bol
0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
LVL 1

Expert Comment

by:alexgcm
ID: 20331270
You can put the following code at the HTML code of the page(not the master one):

<script language="javascript">window.print();</script>
0
 

Author Comment

by:Cragly
ID: 20331315
Hi guys,

Thanks for your posts but neither of these work within an asp.net 2.0 environment using master pages.

Cheers

Cragly
0
 

Accepted Solution

by:
Cragly earned 0 total points
ID: 20345284
Hi guys,

I found a solution to my problem. I just put the following code in my code behind file of the page I want to print. It works like a treat.
if (!ClientScript.IsStartupScriptRegistered("printpage"))
ClientScript.RegisterStartupScript(typeof(Page), "printpage", "<script>window.print();</script>");

Open in new window

0
 

Author Comment

by:Cragly
ID: 20353692
yes , all sorted and keeping the solution and having the points refunded would be great thanks.

Cheers

Cragly
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

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

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…
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
This video teaches viewers how to create their own website using cPanel and Wordpress. Tutorial walks users through how to set up their own domain name from tools like Domain Registrar, Hosting Account, and Wordpress. More specifically, the order in…
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.
Suggested Courses

971 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