Subscribe to Youtube channel

Disable button after click in asp.net

To prevent double submit a form by user we need to restrict the user to click the button again. The idea is that we will use JavaScript to disable the button once user clicks first time.

Add the following lines on .aspx page


<asp:Button ID="btnProcess" runat="server" onclick="btnProcess_Click"
            Text="Process" />

Add the following line on .aspx.cs page (Page_Load).


string strProcessScript = "this.value='Processing...';this.disabled=true;";
        btnProcess.Attributes.Add("onclick", strProcessScript + ClientScript.GetPostBackEventReference(btnProcess, "").ToString());


This will disable Button, and then change the text of the button "Processing...", and then continue on with the server side event btnProcess_OnClick event handler.

Comments

Popular posts from this blog

Root your Gingerbread 2.3.4 android Mobile Phone

Restore the lost focus of Auto post back controls in asp.net update Panel control

Disable backspace key using Jquery

Implement Logging in CSV file using Nlog in .net core MVC application- part 2

Implement Nlog in .Net core MVC application part 1

Angular User Session Timeout example step by step

Devexpress Datebox date formatting in angular 6 with example

How to Import CSV File and bind csv file data to gridview in asp.net using c#

Add Comma automatically while entering amounts in textbox using Javascript