我能够创建测试代码。在FF和铬似乎工作正常(1提交),但IE9(和兼容性版本)似乎打了1,2或3次。 注意:submit()会导致回发。 CASE 1.延迟在Javascript 页:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>testing</title>
<script type="text/javascript">
function submitForm() {
document.forms[0].submit();
alert("delay");
document.forms[0].submit();
}
</script>
</head>
<body>
<form id="form1" name="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server" Width="220px"></asp:TextBox>
<button onclick="submitForm(this)">CLICK</button>
<br />
<asp:Label ID="Label1" runat="server"></asp:Label>
</div>
</form>
</body>
</html>
后面的代码:
protected void Page_Load(object sender, EventArgs e)
{
if(IsPostBack)
{
incrementVal();
}
}
private void incrementVal()
{
var val = (int)(Session["val_" + TextBox1.Text] ?? 0);
val++;
Label1.Text += TextBox1.Text + ": " + val.ToString("00") + " - " + DateTime.Now.ToLongTimeString() + "<br/>";
Session["val_" + TextBox1.Text] = val;
}
案例2:慢速响应
删除JS警报:
function submitForm() {
document.forms[0].submit();
document.forms[0].submit();
}
增加延迟在服务器端:
if(IsPostBack)
{
incrementVal();
Thread.Sleep(500);
}
我重现通过重新加载页面/帧,但事实并非如此。添加用户页面是一个iframe,因此,例如在Firefox中,在确认提醒期间,我们必须右键单击帧>此帧>重新加载帧,然后FF确认。这不是创建这个重复记录的原因。 – Jaider