In the project development, encountered such a situation, is the user repeated submission. Of course this can not blame the user, can only blame. NET or server unresponsive ... That's how I understand it.
Search on the Internet, the solution is quite a few, such as:
http://bbs.csdn.net/topics/340048988
(This has made a lot of suggestions)
Http://www.cnblogs.com/blsong/archive/2009/12/24/1631144.html
(This basically sums up the online method)
But in fact doing Internet web projects, need to perform JS or jquery in the foreground of the validation (mainly to enhance the user experience), then use the above methods, there will be problems. Either the duplicate commit still exists or the foreground JS validation fails. Finally have no way, only write one of their own, in the case of the user to prevent repeated submissions, but also to ensure that the front desk JS validation effective. The code is as follows:
Copy Code code as follows:
Button Registration Load Style event
var Itselfbutton;
var controlregpostresult = true;
function Addinputclick () {
$ ("input[type= ' Submit ']"). Click (function () {
Itselfbutton = $ (this);
if (itselfbutton.attr ("repeat") = = null) {
var Btndiv = $ ("<div>");
BTNDIV.ATTR ("id", "mask_btn");
var divimg = $ ("Divimg.attr ("alt", "Load ...");
Divimg.attr ("src", "/images/buttonloading.gif");
divimg.css {"Margin-left": ($ (this). Width ()-4)/2, "Margin-top": ($ (this). Height ()-16)/2});
Btndiv.append (DIVIMG);
Btndiv.css ({width: $ (this). Width () + + ' px ', Height: $ (this). Height () + ' px ', Top: $ (this). Offset (). Top + px, left: $ (this). Offset (). Left + "px", Position: "Absolute"});
$ (document.body). Append (Btndiv);
SetTimeout (Masktimeoutremove, 200);
}
});
}
$ (function () {
Addinputclick ();
});
$ (window). Resize (function () {
if (Itselfbutton!= null) {
$ ("#Mask_BTN"). CSS ({top:ItSelfButton.offset (). Top + "px", Left:ItSelfButton.offset (). Left + "px"});
}
});
function Maskremove () {
$ ("#Mask_BTN"). Remove ();
}
function Masktimeoutremove () {
if (! Controlregpostresult) {
$ ("#Mask_BTN"). Remove ();
Controlregpostresult = true;
}
}
Which in the JS validation failure will
Copy Code code as follows:
Controlregpostresult = false;
This basically satisfies my purpose.
Buttonloading.gif can be a swirling picture, or it can be as big as a button. Anyway the goal is to cover this layer with the button.