Hi Alexey,
What I'm trying to achieve is to print a page when user clicks on a
button but I don't want this button to get printed with the page.
I just tried the following; printing is fine but the button is always
visible and is printed:
------------------------------------------
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim ret As Boolean = PrintWithJava()
End Sub
------------------------------------------
Private Function PrintWithJava() As Boolean
Dim strScript As String
strScript = "<script language='javascript'>"
strScript +=
"document.getElementById('Button1').style.visibility = 'hidden';"
strScript += "window.print();"
strScript +=
"document.getElementById('Button1').style.visibility = 'visible';"
strScript += "</script>"
Page.ClientScript.RegisterStartupScript(GetType(Page),
"myPrintScript", strScript, False)
Return True
End Function
------------------------------------------
Thanks !
> > Hi,
>
[quoted text clipped - 17 lines]
> step #2. RegisterStartupScript does register a client-side script and
> not execute it.
Alexey Smirnov - 30 Aug 2007 15:28 GMT
> Hi Alexey,
>
[quoted text clipped - 53 lines]
>
> - Show quoted text -
Because, as I wrote, you have to:
1) RegisterStartupScript
2) hide on click via js and not in the code-behind
The PrintWithJava() method in your code does not execute any client-
side script, ASP.NET cannot do it from the server side.
I think, you can delete all that code you made and a Button Control
too.
Instead, add following
<input type="button"
onClick="this.style.visibility='hidden';window.print();this.style.visibility='visible';"
Value="Print">
And try, if it works (I didn't test it)
Mic - 31 Aug 2007 20:07 GMT
Hi Alexey,
I'm lost here because code gets executed with
Page.ClientScript.RegisterStartupScript because printing occurs when
code reaches this line. The name RegisterStartupScript would suggest
that it should only register the script to be used later somehow but
it executes the code.
About your code:
<input type="button"
onClick="this.style.visibility='hidden';window.print();this.style.visibility='visible';"
Value="Print">
Where do I put it and how do I call it ? I thought the Javascript code
would get executed with Page.ClientScript.RegisterStartupScript.
As you can see I'm quite mixed up with this so I really appreciate
your help.
> > Hi Alexey,
>
[quoted text clipped - 72 lines]
>
> And try, if it works (I didn't test it)
Alexey Smirnov - 31 Aug 2007 20:14 GMT
> Hi Alexey,
>
[quoted text clipped - 3 lines]
> that it should only register the script to be used later somehow but
> it executes the code.
Well, maybe I misunderstood you. I'm reading your first post again:
where do you need a button? Do you want to open the print dialog on a
button click or when the page is loaded?