473,800 Members | 2,497 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.I mageClickEventA rgs) Handles ibtnPrint.Click
Try

myFunction() 'do the job before print

Dim sbScript As New System.Text.Str ingBuilder
sbScript.Append ("<script language='javas cript'>")
sbScript.Append (Environment.Ne wLine)
sbScript.Append ("window.print( );")
sbScript.Append (Environment.Ne wLine)
sbScript.Append ("</script>")
RegisterClientS criptBlock("Ope nImp", sbScript.ToStri ng())

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.prin t(), but this will print
me a blank page.

If I put in Page Load this piece of code ibtnPrint.Attri butes.Add("OnCl ick",
"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 1523

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.I mageClickEventA rgs) Handles ibtnPrint.Click
Try

myFunction() 'do the job before print

Dim sbScript As New System.Text.Str ingBuilder
sbScript.Append ("<script language='javas cript'>")
sbScript.Append (Environment.Ne wLine)
sbScript.Append ("window.print( );")
sbScript.Append (Environment.Ne wLine)
sbScript.Append ("</script>")
RegisterClientS criptBlock("Ope nImp", sbScript.ToStri ng())

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.prin t(), but this will print
me a blank page.

If I put in Page Load this piece of code ibtnPrint.Attri butes.Add("OnCl ick",
"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 RegisterClientS criptBlock are injected
in the page right after the form element so you start to print before
the content will be loaded.
Try to use RegisterStartup ScriptBlock instead of
RegisterClientS criptBlock. Maybe give some timeout to allow the page
completely load.
setTimeout("win dow.print();", 100);

Mar 12 '07 #2

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

Similar topics

7
6873
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 only problem with doing this is that a header (name of the page and Page x of x) and footer (actual page filename the date) are included. I am proficient with using Crystal Reports v10 (developers version) which will create a PDF file for you to...
7
9519
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
1769
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. Evan Camilleri
3
6869
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.5cm; } * { display: none; } yet that doesn't produce the desired result. How do I include the single
1
2060
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: ------------------------------------------------------------------------------------------------ Private Sub ibtnPrint_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ibtnPrint.Click Try
0
2216
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 = "<html xmlns:o='urn:schemas-microsoft-com:office:office' " & _ "xmlns:w='urn:schemas-microsoft-com:office:word'" & _ "xmlns='http://www.w3.org/TR/REC-html40'>" strBody = strBody + "<!-->" & _ "<xml>" & _ "<w:WordDocument>" & _
0
5324
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 footer = null; object o = null; InternetExplorerClass ie = null;
0
2118
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 there is input otherwise it changes the template and lists the results on the other template page. That is why there is a $template variable. ==== $template = "template_carlist.html"; if ($_POST!='Open in Excel'){
2
2176
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 otherwise it re-displays the form request. The $template variable changes the value of which template is displayed. if($mark&&$num){ $mark = $mark = strtoupper($mark); $TPL_carnumbers = GetHeaders($_SESSION); $xclheader =
0
9691
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9551
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10507
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10255
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10036
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9092
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6815
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5607
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4150
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.