Print Page and Header

Discussion in 'ASP .Net Web Controls' started by ruca, Mar 7, 2007.

  1. ruca

    ruca Guest

    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
    ruca, Mar 7, 2007
    #1
    1. Advertising

  2. ruca

    marss Guest

    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);
    marss, Mar 12, 2007
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. ashj
    Replies:
    0
    Views:
    2,776
  2. Bernard Segonnes

    Print and print overview and current page

    Bernard Segonnes, Nov 4, 2004, in forum: Java
    Replies:
    0
    Views:
    449
    Bernard Segonnes
    Nov 4, 2004
  3. keto
    Replies:
    0
    Views:
    934
  4. David Cournapeau

    print a vs print '%s' % a vs print '%f' a

    David Cournapeau, Dec 30, 2008, in forum: Python
    Replies:
    0
    Views:
    348
    David Cournapeau
    Dec 30, 2008
  5. mlt
    Replies:
    2
    Views:
    833
    Jean-Marc Bourguet
    Jan 31, 2009
Loading...

Share This Page