Tuesday, November 20, 2012

Disable ASP.NET Button Until Back Ground Task Completes.


This kind of scenario is required when doing a transaction. User clicks on the complete transaction button and we need the user avoid from clicking on the button again. Below code demonstrate how we can achieve this in ASP.NET.






Use the UseSubmitBehavior property to specify whether a Button control uses the client browser's submitmechanism or the ASP.NET post back mechanism. By default the value of this property is true, causing the Button control to use the browser's submit mechanism. If you specify false, the ASP.NET page framework adds client-side script to the page to post the form to the server.
in the code behind on Button1_Click1 we can enable the button at the end of the task.

protected void Button1_Click1(object sender, EventArgs e)
    {
        Thread.Sleep(700); // Process
        Button1.Enabled = true;
    }




No comments:
Write comments
Recommended Posts × +