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
Printable View
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
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
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.
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
1 question...
i need to do this on a web application
is it possible to disable for 2 secs and enable again?
thanks
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:
In case, the need is for exact 2 secs or something..you would be using the timer control as suggested by wildfrog. :thumb: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)
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
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:
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.Code:void Button1_Click(Object sender, EventArgs e)
{
Button1.Enabled = False;
//rest of the processing here.
Button1.Enabled = True
}
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.
thanks :) yeah trying to use javascript now
i think it worked
You are welcome ! and how about spreading some reputation to the helpful/good posts? :D :thumb: