I am creating a button dynamically in my code and attaching a click event to it. However I have to prevent people to click it while there is a process going on. So when it is clicked once, it should be disabled and when the process ends it should be enabled. How can I do that?
Thanks.
To disable a button using only JavaScript you need to set its disabled property to false . For example: element. disabled = true . And to enable a button we would do the opposite by setting the disabled JavaScript property to false .
Try putting a Threading. Thread. Sleep(5000) on the _Click() event on the server and you will see the button is disabled for the time that the server is processing the click event. No need for server side code to re-enable the button either!
Remove button's Click Event You can simply remove the onclick event handler by setting its value as null.
(1)you can disable the controls in javascript and then use GetPostBackEventReference( button id) to submit the webpage. (2)You can use Session to store flag to prevent "double posts". Please check out the following article. u can disable the button by JS using clientside onClick event.
onclick="this.enabled=false" add this from your code behind to your control
btnAdd.Attributes.Add("onclick", "this.enabled=false;");
This link explains in detail http://encosia.com/2007/04/17/disable-a-button-control-during-postback/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With