我發現了這樣一個解決方案,但我的onclick事件已經綁在代碼隱藏處理程序:防止快速提交按鈕點擊?
MyButton.Attributes.Add("onclick", "this.disabled=true;" + Page.ClientScript.GetPostBackEventReference(MyButton, "").ToString());
onclick="this.disabled=true;__doPostBack('MyContrl$MyButton','');"
我的代碼:
<asp:imagebutton id="CheckoutBtn" runat="server" ImageURL="Styles/Images/submit.gif" onclick="CheckoutBtn_Click">
後臺代碼:
protected void CheckoutBtn_Click(object sender, ImageClickEventArgs e)
{
{
MyShoppingCart usersShoppingCart = new MyShoppingCart();
if (usersShoppingCart.SubmitOrder(User.Identity.Name) == true)
{
CheckOutHeader.InnerText = "Thank you.";
Message.Visible = false;
CheckoutBtn.Visible = false;
}
else
{
CheckOutHeader.InnerText = "Submission Failed - Please try again. ";
}
}
}
什麼是你的問題? – JeremyWeir
嗨,我需要防止用戶多次點擊一個提交按鈕,如標題所示。 – k80sg