Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable an asp.net dynamic button click event during postback and enable it afterwards

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.

like image 720
stckvrflw Avatar asked Jan 28 '10 09:01

stckvrflw


People also ask

How do you disable a dynamic button?

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 .

How to disable the button after click in asp net?

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!

How do I block a button click event?

Remove button's Click Event You can simply remove the onclick event handler by setting its value as null.

How can stop multiple clicks on submit button in asp net?

(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.


1 Answers

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/

like image 188
Ravi Vanapalli Avatar answered Sep 27 '22 18:09

Ravi Vanapalli