1: <html xmlns="http://www.w3.org/1999/xhtml">
2: <head runat="server">
3: <script type="text/javascript">
4: var date = new Array();
5: function disableButton(button, validateGroup)
6: {
7: date.push(new Date());
8: if (date.length > 1
9: && (date[date.length - 1].getTime() - date[date.length - 2].getTime() < 1000))//小于1秒则认为重复提交
10: {
11: event.cancelBubble = true; //测试时发现,如果直接单独设置cancelBubble、或者returnValue来取消事件,经常取消不了,依然存在重复提交的可能。因此只好用返回值来实现手工控制!
12: return false;
13: }
14: if (typeof (Page_ClientValidate) == 'function'
15: && ((validateGroup == undefined && Page_ClientValidate() == false)
16: || (validateGroup != undefined && Page_ClientValidate(validateGroup) == false)))
17: { //如果指定了ValidateGroup,则只验证改组;如果未指定,则验证全部验证控件
18: return false;
19: }
20:
21: button.disabled = true;
22: return true;
23: }
24:
25: function doubleClick()
26: {
27: var button1 = document.getElementById('btnPostBack1');
28: button1.onclick();
29: button1.onclick();
30: }
31: </script>
32: </head>
33: <body>
34: <form id="form" runat="server">
35: <div>
36: <asp:TextBox runat="server" ID="tbxInput1"></asp:TextBox>
37: <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="tbxInput1"
38: ValidationGroup="Group1" ErrorMessage="*"></asp:RequiredFieldValidator>
39: <asp:Button runat="server" ID="btnPostBack1" Text="按我1" UseSubmitBehavior="false"
40: ValidationGroup="Group1" OnClientClick="if(!disableButton(this, 'Group1')) return false;" OnClick="btnPostBack_Click">
41: </asp:Button>
42: </div>
43: <div>
44: <asp:TextBox runat="server" ID="tbxInput2"></asp:TextBox>
45: <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="tbxInput2"
46: ValidationGroup="Group2" ErrorMessage="*"></asp:RequiredFieldValidator>
47: <asp:Button runat="server" ID="btnPostBack2" Text="按我2" UseSubmitBehavior="false"
48: OnClientClick="if(!disableButton(this)) return false;" OnClick="btnPostBack_Click">
49: </asp:Button>
50: </div>
51: <input type="button" onclick="doubleClick();" value="点击一次,模拟连续点击'按我1'两次" />
52: </form>
53: </body>
54: </html>