Wednesday, August 19, 2009
#
A few days ago I got an error report to fix. Some web application that I now maintain was inserting duplicate records.
After a quick look it became obvious that the users where double clicking the submit button and that made the page post twice and so a duplicate record would appear.
A quick fix dor this problem using javascript:
<script language="javascript" type="text/javascript">
var haveSubmitted=false;
function FirstSubmitOnly() {
if (haveSubmitted)
return false;
haveSubmitted = true;
return true;
}
</script>
And at the form tag just invoke the function <form id="form1" runat="server" onsubmit="return FirstSubmitOnly();">
Enjoy :)