473,395 Members | 1,677 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Print Page and Header

Hi,

I have a button that when clicked must print the current page after doing
something in a certain function. For that I have this code:

------------------------------------------------------------------------------------------------
Private Sub ibtnPrint_Click(ByVal sender As System.Object, ByVal e As
System.Web.UI.ImageClickEventArgs) Handles ibtnPrint.Click
Try

myFunction() 'do the job before print

Dim sbScript As New System.Text.StringBuilder
sbScript.Append("<script language='javascript'>")
sbScript.Append(Environment.NewLine)
sbScript.Append("window.print();")
sbScript.Append(Environment.NewLine)
sbScript.Append("</script>")
RegisterClientScriptBlock("OpenImp", sbScript.ToString())

Catch ex As Exception
lblMsgErro.Text = ex.Message()
End Try
End Sub
------------------------------------------------------------------------------------------------
This is not opening the print dialog. I'm using frames in application, and
already change the window.print() to top.window.print(), but this will print
me a blank page.

If I put in Page Load this piece of code ibtnPrint.Attributes.Add("OnClick",
"window.print();") then dialog opens ok. The problem is how can I do the job
that is doing in myFuncion method.
How can I resolve this?!?!?!?!?!?!?!?!?
I have another question: Can I change in code the header and footer of the
page that I'm printing? How?

--
Programming ASP.NET with VB.NET

Thank's (if you try to help me)
Hope can help (if I try to help)

ruca
Mar 7 '07 #1
1 1510

ruca wrote:
Hi,

I have a button that when clicked must print the current page after doing
something in a certain function. For that I have this code:

------------------------------------------------------------------------------------------------
Private Sub ibtnPrint_Click(ByVal sender As System.Object, ByVal e As
System.Web.UI.ImageClickEventArgs) Handles ibtnPrint.Click
Try

myFunction() 'do the job before print

Dim sbScript As New System.Text.StringBuilder
sbScript.Append("<script language='javascript'>")
sbScript.Append(Environment.NewLine)
sbScript.Append("window.print();")
sbScript.Append(Environment.NewLine)
sbScript.Append("</script>")
RegisterClientScriptBlock("OpenImp", sbScript.ToString())

Catch ex As Exception
lblMsgErro.Text = ex.Message()
End Try
End Sub
------------------------------------------------------------------------------------------------
This is not opening the print dialog. I'm using frames in application, and
already change the window.print() to top.window.print(), but this will print
me a blank page.

If I put in Page Load this piece of code ibtnPrint.Attributes.Add("OnClick",
"window.print();") then dialog opens ok. The problem is how can I do the job
that is doing in myFuncion method.
How can I resolve this?!?!?!?!?!?!?!?!?

Hi,
The script blocks registered by RegisterClientScriptBlock are injected
in the page right after the form element so you start to print before
the content will be loaded.
Try to use RegisterStartupScriptBlock instead of
RegisterClientScriptBlock. Maybe give some timeout to allow the page
completely load.
setTimeout("window.print();", 100);

Mar 12 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Robert Adkison | last post by:
I need to print a web page. It is my preference that my users just do a File/Print from explorer. That way my users will get the print dialog that will allow them to select the fax printer. The...
7
by: Neil Jarman | last post by:
Hi, I would like to allow users to print a page, but I want to suppress the header and footer that appear by default. I gather its done with a style sheet. Please advise. Many Thanks,
7
by: Evan Camilleri | last post by:
I have a datagrid with headers. I managed to 'freeze' the headers OK and then one can scroll to see contents. I would like to be able to print this list by re-prinitng the headers on each page....
3
by: Otto Wyss | last post by:
I'd like to print a page but would exclude all elements but one (a table). I've successfully removed all elements from printing with a print.css @page { size: portrait; margin: 2.5cm 1cm 1.5cm...
1
by: ruca | last post by:
Hi, I have a button that when clicked must print the current page after doing something in a certain function. For that I have this code: ...
0
by: krishnagovindaraj | last post by:
Hi, I have to create word document with header and footer..its working in web layout.In Print Layput,the header is displayed two times..Plz give me the solution...its very urgent.. strBody =...
0
by: Andrew Meador | last post by:
I have implemented a printing scenario where an html file is printed using the the following code: public void PrintHtmlFile(string url) { RegistryKey IERegKey; string header = null; string...
0
by: JRough | last post by:
I have the following code at the end of a page that lists some query results. It starts in a form that asks the user for input, one of two template pages. One template is a form for user input if...
2
by: JRough | last post by:
I have this code that switches templates depending on if the user fills in a form with a request. The request asks for the $mark & $number. If that request gets input then it displays a list...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.