asp.net form submission and execute the front desk JS Verification _ practical Skills

Source: Internet
Author: User
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.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.