It is amazing how may people out there still apply the double click paradigm to web applications.

What is frustrating is that some of the most simple methods for preventing the double click stop ASP.Net from firing the appropriate click event when the page is posted back.

A while ago Evgeny posted an article on how to prevent double clicks on buttons in ASP.Net. This solution was a little code heavy for my liking and so after a bit of playing around i came up with this simple jQuery solution.

That is where this little jQuery script come in. When the user clicks an input with the class of ‘button’ we will apply an attribute to it so that the next time the user clicks it, the event wont fire again. Easy!


$(document).ready(function () {
    //prevent double clicks
    $(".button").click(function () {
        if ($(this).attr("dblclick") != "true")
            $(this).attr("dblclick", "true");
        else
            return false;
    });
});



You may also like

Linq – SubmitChanges does not work

This is one of those very annoying things you just have to ask the developers of the Linq Library: “Why don’t you throw an exception for us??” When you use Linq to SQL you need to make sure that the table has a primary key specified. Otherwise when you call SubmitChanges nothing will happen!

Keep Reading

Unique Arrays in PHP

I was recently working on a PHP application for a Client where I was faced with a Multi-Dimensional Array filled with duplicate entries and a lot of unusable data. What I needed was to extract all the unique elements of the Array so I had some clean data to work with. 

Keep Reading

Newsletter sign up

Every couple of months we send out an update on what's been happening around our office and the web. Sign up and see what you think. And of course, we never spam.