Solved

Disable a button for 2 seconds

Posted on 2014-01-10
8
416 Views
Last Modified: 2014-01-11
I just want a suggestion from someone with experience.  I would like to disable a button ( and possibly make it grey) for a second or two after it was clicked.  After 2 seconds it should re-enable so if the user really wants to click it multiple times they can.
Thank you in advance or your advice.
0
Comment
Question by:wilfordrocks
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 12

Expert Comment

by:ktaczala
ID: 39772899
Set up a separate thread(using BackgroundWorker) to count for 2 seconds.  Then when the thread completes, re-enable the button.  By putting it on a separate thread normal operation will not pause in your application.
0
 
LVL 40
ID: 39773345
Put a Timer Control on the Form and set its Interval property to 2000.

In the Click event of the button, start the timer and disable the button:

            Timer1.Start()
            Button1.Enabled = False

In the Tick event of the timer, reenable the Button

            Button1.Enabled = True
0
 

Author Comment

by:wilfordrocks
ID: 39773370
That is kind of a windows way of doing it.  I suspect Java or jquery has a browser way of doing it.  thanks for your input.  I will leave the question open a little longer.
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 40
ID: 39773378
Ooops. Sorry, I did not see your Tags.

Try to be more precise in your Topics. ExpertExchange uses the topics to flag experts, and you have more chances of having your question falling in the right hands if you specify less general topics.
0
 
LVL 35

Expert Comment

by:Robert Schutt
ID: 39773515
With plain javascript you could use something like this:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>EE Q_28335925</title>

<script type='text/javascript'>
var g_sbm = null;
function temp_disable(sbm, tm) {
    g_sbm = sbm;
    toggle_sbm();
    setTimeout(toggle_sbm, tm);
}
function toggle_sbm() {
    g_sbm.disabled = !g_sbm.disabled;
}
</script>

</head>
<body>

<form name="frm" action="" method="post" onsubmit="return false;">
  <input name="name">
  <input name="sbm" id="sbm" type="submit" onclick="temp_disable(this, 2000)">
</form>

</body>
</html>

Open in new window

0
 
LVL 35

Accepted Solution

by:
Robert Schutt earned 500 total points
ID: 39773528
quick addition for the color:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>EE Q_28335925</title>

<script type='text/javascript'>
var g_sbm = null, g_sbmcol;
function temp_disable(sbm, tm) {
    g_sbm = sbm;
    g_sbmcol = g_sbm.style.backgroundColor;
    toggle_sbm();
    setTimeout(toggle_sbm, tm);
}
function toggle_sbm() {
    g_sbm.disabled = !g_sbm.disabled;
    g_sbm.style.backgroundColor = g_sbm.style.backgroundColor == g_sbmcol ? 'gray' : g_sbmcol;
}
</script>

</head>
<body>

<form name="frm" action="" method="post" onsubmit="return false;">
  <input name="name">
  <input name="sbm" id="sbm" type="submit" onclick="temp_disable(this, 2000)" style="color: white; background-color: green;">
</form>

</body>
</html>

Open in new window

0
 

Author Comment

by:wilfordrocks
ID: 39773923
This is beautiful and elegant.  Thank you.
Just to make sure I understand the variable names.
'g_'  means global?
'sbm'  stands for submit?
'col'  is color?

Again, thank you.
0
 
LVL 35

Expert Comment

by:Robert Schutt
ID: 39773929
yep, 3 out of 3 :-)

And thank you!
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question