Click here to Skip to main content
15,908,675 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
protected void Button1_Click(object sender, EventArgs e)
    {
        Button1.Enabled = false;
        try
        {
            // put your code here
        }
        finally
        {
            Button1.Enabled = true;
        }
        
    }


i wrote this code still button not disable and enable why
Posted

because you used finally block, that's why button is not disabling.

if you are using try-catch-finally

then finally will be executed if error occurs or not and the same happening to your code.


Read this -

http://msdn.microsoft.com/en-us/library/dszsf989%28v=vs.80%29.aspx[^]
 
Share this answer
 
You enable your button in finally block.
C#
finally
       {
           Button1.Enabled = true;
       }

use
C#
try
{
}
catch
{
Button1.Enabled = true;
}
 
Share this answer
 
Comments
Prasad_Kulkarni 26-Apr-12 2:16am    
I din't thought this solution, good one +5!
uspatel 26-Apr-12 2:17am    
Thanks Prasad......
C#
Button1.Enabled = false;
        try
        {
            // put your code here
        }
       catch
        {
            Button1.Enabled = true;
        }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900