Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / August 2007

Tip: Looking for answers? Try searching our database.

How to hide and show a button after executing javascript function

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mic - 29 Aug 2007 23:26 GMT
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
Alexey Smirnov - 29 Aug 2007 23:41 GMT
> Hi,
>
[quoted text clipped - 13 lines]
>
> 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.
Mic - 30 Aug 2007 14:54 GMT
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?

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.