CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10
  1. #1
    Join Date
    May 2005
    Posts
    23

    Exclamation disable button for a while after clicked

    hello

    i need to disable my button after user clicked it, but only for a while, say 2 seconds.

    how should i do this?


    tq

  2. #2
    Join Date
    Apr 2005
    Location
    Norway
    Posts
    3,934

    Re: disable button for a while after clicked

    You can use the System.Windows.Forms.Timer class. When the button is clicked, disable it and start the timer (with a 2 second interval). Then when the timers Tick event occur, enable the button and stop the timer.

    - petter

  3. #3
    Join Date
    May 2003
    Location
    Germany
    Posts
    936

    Re: disable button for a while after clicked

    I would do it by events. If the button is clicked for the first time you disable the button and call your method for executing the logically instructions related to that button. After this instructions are all finished you can raise an event and enable the button again. So you are prepared if a constant timespan of x seconds are not enough or too long. You have disabled the button exactly for the time you need to do some actions.
    Useful or not? Rate my posting. Thanks.

  4. #4
    Join Date
    May 2005
    Posts
    23

    Re: disable button for a while after clicked

    i did the process on a delegate - callback. so i just need to let it disabled for 2 senconds.

    thanks for ur suggestions !!

    i'll try both

  5. #5
    Join Date
    May 2005
    Posts
    23

    Re: disable button for a while after clicked

    1 question...
    i need to do this on a web application
    is it possible to disable for 2 secs and enable again?

    thanks

  6. #6
    Join Date
    Feb 2005
    Location
    "The Capital"
    Posts
    5,306

    Thumbs up Re: disable button for a while after clicked

    Why do u need to disable it for 2 secs? Must be so that users don't click it again before the processing at its click event has happened once. Am I right??? In that case, no need to raise an event or use timers. Use this:
    Code:
    //Inside your button click event
    Button1.Enabled = False;
    //rest of the processing here.
    Button1.Enabled = True
    //end of the button click event (method scope)
    In case, the need is for exact 2 secs or something..you would be using the timer control as suggested by wildfrog.

  7. #7
    Join Date
    May 2005
    Posts
    23

    Re: disable button for a while after clicked

    i need it because i dont want the same user to click on the button at the same second, as i'm using time and username for the name of file created upon click

  8. #8
    Join Date
    Feb 2005
    Location
    "The Capital"
    Posts
    5,306

    Thumbs up Re: disable button for a while after clicked

    Yes, so follow the way I have traced. Thats simple and the best solution to it. So, the button's click event would look something like this:
    Code:
          void Button1_Click(Object sender, EventArgs e) 
          {
                Button1.Enabled = False;
                //rest of the processing here.
                Button1.Enabled = True
          }
    Since you have a web-form. I dont think you even need to worry about it? Do you? Anyways, in that case you might need to use some Javascript code for the client side to handle the enabling and disbaling of the button.
    write a javascript function that is set with the "onclick" attribute of the button. I dont think that server side code is going to help you with this. Hope this helps.
    Last edited by exterminator; July 18th, 2005 at 01:14 AM.

  9. #9
    Join Date
    May 2005
    Posts
    23

    Re: disable button for a while after clicked

    thanks yeah trying to use javascript now
    i think it worked

  10. #10
    Join Date
    Feb 2005
    Location
    "The Capital"
    Posts
    5,306

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured