问题: 用户发邮件说他发现有时候收三遍同样的邮件。
过程:我先开始看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;
}