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

Use Chroma DB vector database in RAG application using llama index & Deepseek R1 local model

I have created an application to extract text from image using AI

Download DeepSeek R1 Model Locally free | AI RAG with LlamaIndex, Local Embedding and Ollama

Understanding the Singleton Design Pattern in C#

Create Chat bot application using Python, Streamlit and Gemini AI