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

stckvrflw picture stckvrflw · Jan 28, 2010 · Viewed 13.7k times · Source

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.

Answer

Ravia picture Ravia · Jan 28, 2010

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/