In many cases, we need to prevent repeated submissions. There are also many articles in this regard, and there are great differences in implementation methods. the following is a control submission method I wrote. sometimes, even if the server can identify repeated submissions, it may cause problems. for example, if an operation that takes a long wait time is submitted repeatedly after the first submission, the page may die. this problem can be prevented by using scripts. of course, it can also be controlled by both the script and the server, which is perfect.
In other words, place the following script on the top of the page.
1document. isposted = false;
2 function canceldubsubmit ()
3 {
4 If (typeof (event. returnvalue) = "undefined" | event. returnvalue = true )&&! Document. isposted)
5 {
6 Document. isposted = true;
7 event. returnvalue = true;
8}
9 else
10 {
11 event. returnvalue = false;
12}
13}
The following bold parts are placed in the form tag. If you already have other execution functions of the onsubmit event, you can put them together. It is best to put the canceldubsubmit () function at the end. <Form ID = "form1"Onsubmit= "Canceldubsubmit ();"Method = "Post" runat = "server">
Where document. isposted is used to record whether to send back. once the page is sent back, document. isposted will be true. after reload, document. isposted = false will be executed. when the onsubmit event does not have other execution functions or other execution functions, return true and document. if isposted is set to false, the return page is displayed. Otherwise, the return page is stopped.
The above method cannot control the server-side controls using the function _ dopostback () function. because the submission in this function depends on document. form1.submit (), which does not trigger the onsubmit event. we also need to rewrite the _ dopostback () function. function _ dopostback (eventtarget, eventargument ){
If (! Document. isposted)
{
VaR theform;
If (window. Navigator. appname. tolowercase (). indexof ("Netscape")>-1 ){
Theform = Document. Forms ["form1"];
}
Else {
Theform = Document. form1;
}
Theform. _ eventtarget. value = eventtarget. Split ("$"). Join (":");
Theform. _ eventargument. value = eventargument;
Document. isposted = true;
Theform. Submit ();
}
}
Place the above Code after the original _ dopostback () function of the page.