Sunday, February 7, 2010

How to disable multiple button click in

Please visit my new Web Site

Disabling or preventing multiple mouse button click event on page is a common task. Specially when you want to develop an e-commerce site client must want to disable the payment button after first click of the user. So that user can't click twice or double or multiple time.Normally we have used an onclick javascript event to diable the button after first click. In each serverside control has already a onclick event to do the same thing in

Basically my approach is different from others. Here i will register the javascript onclick attributes in the run time means page_load event & after that i give the command to execute the server side event.

To understand what i am trying to do look at the below sequences where when user click on the button i will disable the button & after completion the button will enable soon. If you redirect from this page then no problem.


Just use the below line code under page_load event:
cmdSubmit.Attributes.Add("onclick", "this.disabled=true;" + ClientScript.GetPostBackEventReference(cmdSubmit,"").ToString());
Where cmdSubmit is our button which we dont want to click twice or more.

Now complete ths example add a page in your project. The HTML MARKUP code is given below:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Disable_Multiple_button_click.aspx.cs" Inherits="Disable_Multiple_button_click" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="" >
<head runat="server">
    <title>How to disable multiple button click</title>
    <form id="form1" runat="server">
    <asp:Button runat="server" ID="cmdSubmit" Text="Clcik Me" OnClick="cmdSubmit_Click" />
The complete serverside code is given below:
using System;

public partial class Disable_Multiple_button_click : System.Web.UI.Page
    protected void Page_Load(object sender, EventArgs e)
        cmdSubmit.Attributes.Add("onclick", "this.disabled=true;" + ClientScript.GetPostBackEventReference(cmdSubmit,"").ToString());
    protected void cmdSubmit_Click(object sender, EventArgs e)
        Response.Write("I have clicked : "+DateTime.Now.ToString());
Hope now you can restrict or prevent the user from twice or more than one or from multiple mouse click.


sikat ang pinoy said...

Oh noh another version has been release this year blogengine 1.6. It has new additional features now it can prevent comment spam filter that has ability to plugin custom filtering modules.It has improve outgoing emails and more improvement and fixes for this 1.6 version.

kannadasan said...

given above code is working Local but after deployment is not working on azure.

Anonymous said...

Realy work ,thanks allot
I find this solution after a lot of googling
thanks once again

Want to say something?

Want To Search More?
Google Search on Internet
Subscribe RSS Subscribe RSS
Article Categories
  • Gridview
  • Javascript
  • AJAX
  • Sql server
  • XML
  • CSS
  • Free Web Site Templates
  • Free Desktop Wallpapers
  • TopOfBlogs
    Free ASP.NET articles,C#.NET,VB.NET tutorials and Examples,Ajax,SQL Server,Javascript,Jquery,XML,GridView Articles and code examples -- by Shawpnendu Bikash