|
-
July 15th, 2005, 03:49 AM
#1
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
-
July 15th, 2005, 03:59 AM
#2
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
-
July 15th, 2005, 04:10 AM
#3
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.
-
July 15th, 2005, 04:17 AM
#4
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
-
July 15th, 2005, 04:46 AM
#5
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
-
July 15th, 2005, 04:52 AM
#6
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.
Can you help me with my homework assignment?, Before you post!, Use code tags, How to post!, Codeguru technical FAQs, C++ FAQ Lite, Stroustrup: C++ Style and Technique FAQ, Guru of the Week, Comeau C and C++ FAQs, Comeau C++ Templates FAQs, CUJ @ DDJ, Spam threshold
My Blogs : Learning C++ is fun | Abnegator's reflections
Open Threads : C++ Aha! Moments | Nature of work in C++?
-
July 17th, 2005, 02:27 AM
#7
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
-
July 18th, 2005, 01:10 AM
#8
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.
Can you help me with my homework assignment?, Before you post!, Use code tags, How to post!, Codeguru technical FAQs, C++ FAQ Lite, Stroustrup: C++ Style and Technique FAQ, Guru of the Week, Comeau C and C++ FAQs, Comeau C++ Templates FAQs, CUJ @ DDJ, Spam threshold
My Blogs : Learning C++ is fun | Abnegator's reflections
Open Threads : C++ Aha! Moments | Nature of work in C++?
-
July 18th, 2005, 02:48 AM
#9
Re: disable button for a while after clicked
thanks yeah trying to use javascript now
i think it worked
-
July 18th, 2005, 04:20 AM
#10
Re: disable button for a while after clicked
You are welcome ! and how about spreading some reputation to the helpful/good posts?
Can you help me with my homework assignment?, Before you post!, Use code tags, How to post!, Codeguru technical FAQs, C++ FAQ Lite, Stroustrup: C++ Style and Technique FAQ, Guru of the Week, Comeau C and C++ FAQs, Comeau C++ Templates FAQs, CUJ @ DDJ, Spam threshold
My Blogs : Learning C++ is fun | Abnegator's reflections
Open Threads : C++ Aha! Moments | Nature of work in C++?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|