Click to See Complete Forum and Search --> : disable button for a while after clicked
duckduck
July 15th, 2005, 03:49 AM
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
wildfrog
July 15th, 2005, 03:59 AM
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
torrud
July 15th, 2005, 04:10 AM
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.
duckduck
July 15th, 2005, 04:17 AM
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
duckduck
July 15th, 2005, 04:46 AM
1 question...
i need to do this on a web application
is it possible to disable for 2 secs and enable again?
thanks
exterminator
July 15th, 2005, 04:52 AM
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:
//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. :thumb:
duckduck
July 17th, 2005, 02:27 AM
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
exterminator
July 18th, 2005, 01:10 AM
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:
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.
duckduck
July 18th, 2005, 02:48 AM
thanks :) yeah trying to use javascript now
i think it worked
exterminator
July 18th, 2005, 04:20 AM
You are welcome ! and how about spreading some reputation to the helpful/good posts? :D :thumb:
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.