Print Page and Header

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ruca

    #1

    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


  • marss

    #2
    Re: Print Page and Header


    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);

    Comment

    Working...