Print Page and Header

R

ruca

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
 
M

marss

ruca said:
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);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top