我能夠創建測試代碼。在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;
}
![enter image description here](https://i.stack.imgur.com/IATyI.png)
案例2:慢速響應
刪除JS警報:
function submitForm() {
document.forms[0].submit();
document.forms[0].submit();
}
增加延遲在服務器端:
if(IsPostBack)
{
incrementVal();
Thread.Sleep(500);
}
我重現通過重新加載頁面/幀,但事實並非如此。添加用戶頁面是一個iframe,因此,例如在Firefox中,在確認提醒期間,我們必須右鍵單擊幀>此幀>重新加載幀,然後FF確認。這不是創建這個重複記錄的原因。 – Jaider