My method of avoiding duplication of data submission, I do not dare to enjoy, I hope to help you

Source: Internet
Author: User
Data | repeat | Submission of data in ASP is a very important and common link, how to avoid duplication of data submission is a common problem, there are 2 ways to repeat the general data: first, refresh the submitted page, you will be prompted to resend the message, select Retry will be repeated; So a lot of people are asking how to ban the back button, which at least is not really possible at the moment.

My idea is: when submitting data to do data validation, verification through the opening of a "hidden" window (in fact, is displayed in a small window outside the screen) for submission processing, data saved successfully refresh the parent window and alert display save state and then close this implied window, This way the user cannot return with the back and the submitted window is closed to avoid duplicate refreshes.

Here is my demo, only 2 files: submitdemo.asp and save.asp, very simple, as long as a little modification can be applied to your program, I hope to help.

1.submitdemo.asp Demo data entry and verify main program
------------------------------------------

<title>new/edit</title>
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<script language= "JavaScript" >
<!--
Open a window outside the screen
function Newhidewindow (mypage,myname)
{
Leftposition = parseint (screen.width) +1;
Topposition = parseint (screen.height) +1;
Settings = ' height=100,width=100,top= ' +topposition+ ', left= ' +leftposition+ ', scrollbars=0,resizable=0,status=0 '
window.open (mypage,myname,settings)
}
Data validation function
function Validate (theform)
{
if (TheForm.text1.value = "")
{
Alert ("Please fill in the Text1 data!");
TheForm.text1.focus ();
return (false);
}
if (TheForm.text2.value = "")
{
Alert ("Please fill in the TEXT2 data!");
TheForm.text2.focus ();
return (false);
}
return (true);
}
Call the above two functions to validate the entered data and open the Save Data window
function Savewin (theform)
{
if (Validate (theform))
{
Newhidewindow (' About:blank ', ' Savewindow ');
return true;
}
return false;
}
-->
</script>

<body bgcolor= "#FFFFFF" >
<!--note that the onsubmit function call here and the window name in target are consistent with the window name Newhidewindow written in the Savewin function (note case)-->
<form name= "Form1" action= save.asp "onsubmit=" return Savewin (this); "target=" Savewindow ">
Text1:
<input type= "text" name= "Text1" ><br>
Text2:
<input type= "text" name= "Text2" >
<input type= "Submit" name= "Submission" value= "submitted" >
</form>
</body>


2.save.asp Save Data processing
------------------------

<%
Dim Intstatus
'**********************************************************
' * Save data to the database, where it is best to make a legal check of the data again *
'*  ...                                                   *
' * If Save Success Then *
' * intstatus = 1 *
' * Else *
' * Intstatus =-1



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.