Prevent the user click a button twice

本文描述了一个关于用户收到重复邮件的问题及其解决方案。原因是用户多次点击提交按钮导致数据库中出现重复条目,每次条目触发一封邮件。通过添加JavaScript来禁用提交按钮解决了此问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

问题: 用户发邮件说他发现有时候收三遍同样的邮件。

过程:我先开始看code,发现并没有问题,然后发邮件给wendy说没问题,想知道详情。安娜这时候发邮件说可能是duplicate的entries,由于没有submitOnce这样的button control。我恍然大明白了,以为我也偶然发现怎么出了两个同样的entries,但是没有在意。

原因:现在想想,是因为没有disable sumit button,用户点了两次,DB里有了两个三个同样的entries,然后在code出邮件时,是个while语句,每个entry都会发一个邮件。

解决:找到之前老头写的文件,发现非常easy,加进去js文件,在master里面引用,在submit button那里指向,五分钟完事。

附文件:

function submitOnce(myButton)
{
	//	JavaScript to disable a button after being pressed
	//	Written by Joel Montrose on 9/11/2012
	//
	//	To use this JavaScript, take the following steps: 
	//		1.	Add this file ("SubmitOnce.js") to the form.
	//		2.	Include the following line of code in the Master Page within the <Head> section:
	//			<script src="SubmitOnce.js" type="text/javascript"></script>
	//		3.	Modify each Button code as follows:
	//			Change button from:
	//	<asp:Button ID="btnSubmit" runat="server" Text="Submit Request" OnClick="btnSubmit_Click" />
	//			to:
	//	<asp:Button ID="btnSubmit" runat="server" Text="Submit Request" OnClick="btnSubmit_Click"
	//	OnClientClick="submitOnce(this);" UseSubmitBehavior="false" CausesValidation="false" />
	//
	//	Client-side validation
	if (typeof (Page_ClientValidate) == 'function')
	{
		if (Page_ClientValidate() == false)
		{
			return false;
		}
	}

	//	make sure the button is not of type "Submit" but "Button"
	if (myButton.getAttribute('type') == 'button')
	{
		//	disable the button
		myButton.disabled = true;
		myButton.value = "processing...";
	}
	return true;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值