This article provides you with a prevention of repeated submission of Web page special effects code Oh, you can prevent users from constantly click to submit the form, we will only submit once oh.
<html xmlns= "http://www.jzread.com/1999/xhtml" >
<head runat= "Server" >
<script type= "text/web Effects" >
var date = new Array ();
function Disablebutton (button, Validategroup)
{
Date.push (new Date ());
if (Date.length > 1
&& (Date[date.length-1].gettime ()-Date[date.length-2].gettime () < 1000)//less than 1 seconds is considered duplicate commit
{
Event.cancelbubble = true; Test found that if directly set cancelbubble, or ReturnValue to cancel the event, often canceled, there is still the possibility of duplicate submissions. So we have to use the return value to achieve manual control!
return false;
}
if (typeof (page_clientvalidate) = = ' function '
&& ((Validategroup = = undefined && page_clientvalidate () = False)
|| (Validategroup!= undefined && page_clientvalidate (validategroup) = False))
{//If Validategroup is specified, only the reorganization is validated; if not specified, validate all validation controls
return false;
}
Button.disabled = true;
return true;
}
Function DoubleClick ()
{
var button1 = document.getElementById (' Btnpostback1 ');
Button1.onclick ();
Button1.onclick ();
}
</script>
</head>
<body>
<form id= "form" runat= "Server" >
<div >
<asp Tutorial: TextBox runat= "Server" id= "TBXINPUT1" ></asp:textbox>
<asp: RequiredFieldValidator id= "Requiredfieldvalidator1" runat= "Server" controltovalidate= "TBXINPUT1"
validationgroup= "group1" errormessage= "*" ></asp:requiredfieldvalidator>
<asp:button runat= "server "Id=" Btnpostback1 "text=" 1 "usesubmitbehavior=" false "
validationgroup=" group1 "onclientclick=" if (! Disablebutton (This, ' group1 ')] return false; "onclick= Btnpostback_click >
</asp:button>
</div >
<div>
<asp:textbox runat= "Server" id= "Tbxinput2" ></asp:textbox>
<asp: RequiredFieldValidator id= "Requiredfieldvalidator2" runat= "Server" controltovalidate= "Tbxinput2"
validationgroup= "group2" errormessage= "*" ></asp:requiredfieldvalidator>
<asp:button runat= " Server "id=" Btnpostback2 "text=" 2 "usesubmitbehavior=" false "
onclientclick=" if (!disablebutton (this)) return false; "onclick=" Btnpostback_click >
</asp:button>
</div>
<input type= "button" onclick = "DoubleClick ();" Value= "Click once, simulate consecutive clicks ' Press me 1 ' two times"/>
</form>
</body>
</html>