How to hide and show a button after executing javascript function

M

Mic

Hi,

How can I hide a button before executing a javascript function and
make it visible again after execution of the javascript function?

What I need to do is:

VB Page_Load:
1) Hide Button1: Button1.Visible = False
2) Execute JavaScript (I'm using
Page.ClientScript.RegisterStartupScript)
3) Show Button1: Button1.Visible = True

I am new using these mixed languages and I have not been able to do
it.

Thanks
 
G

Guest

Hi,

How can I hide a button before executing a javascript function and
make it visible again after execution of the javascript function?

What I need to do is:

VB Page_Load:
1) Hide Button1: Button1.Visible = False
2) Execute JavaScript (I'm using
Page.ClientScript.RegisterStartupScript)
3) Show Button1: Button1.Visible = True

I am new using these mixed languages and I have not been able to do
it.

Thanks

Mic, you have to do 1st and 3rd steps using a javascript after you did
step #2. RegisterStartupScript does register a client-side script and
not execute it.
 
M

Mic

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
 
G

Guest

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 !




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

Mic

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.
 
G

Guest

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.

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?
 

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,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top