防止用户多次单击提交 [英] Prevent user from clicking submit multiple times

查看:68
本文介绍了防止用户多次单击提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已禁用网页上的提交"按钮,以防止用户多次提交它.当用户单击提交"按钮时,我只希望将用户数据保存到数据库一次.
在大多数情况下,它运行良好,但有时我最终在数据库中有多个相同记录的条目.我在这里做错什么了吗?还有其他建议吗?

I have disabled the Submit button on my web page to prevent users from submitting it multiple times. I want to save user data only once into the database when user hit the submit button.
Most of the time it works fine but sometime I ended up having multiple entries of same records in database. Is there anything that I am doing wrong here ? Any other suggestion ?

StringBuilder sbValid = new StringBuilder();

            sbValid.Append("if (typeof(Page_ClientValidate) == 'function') { ");

            sbValid.Append("if (Page_ClientValidate('RequiredFields') == false) { return false; }} ");

            sbValid.Append("this.value = 'Please wait...';");

            sbValid.Append("this.disabled = true;");


            //GetPostBackEventReference obtains a reference to a client-side script function that causes the server to post back to the page.

            sbValid.Append(this.Page.GetPostBackEventReference(this.btnSubmit));

            sbValid.Append(";");

            this.btnSubmit.Attributes.Add("onclick", sbValid.ToString());



RequiredFields是该页面上的验证控制组的名称.

这种情况下最糟糕的事情是我无法重现该问题.这是非常随机的. :(



RequiredFields is the name of validation control group on that page.

The worst thing about this situation is I cannot recreate the issue. It is very random. :(

推荐答案



那刷新按钮呢?您已禁用提交"按钮,但用户仍可以按刷新"按钮!我认为您的问题可能是由于刷新页面或按F5键造成的.
Hi,

What about refresh button?! you have disabled your submit button but user can still press refresh button! I think your problem might be because of Refreshing page or pressing F5!
check it out.


你好,

我们可以在回发期间禁用该按钮.本文可能会有所帮助

在回传期间使用AJAX加载背景图片禁用ASP.NET按钮控件 [
hello,

We can disable the button during postback. This article might help

Disable an ASP.NET Button Control During Postback with an AJAX Loading Background Image[^]


用于避免多种形式提交,
避免提交多个表单 [
For avoiding multiple form submits,
Avoid Multiple Form Submits[^]

And also do,

1. Add validation business rules in class level or DB level.
2. After saving data, redirect the page so that you can prevent the duplicate entry on F5/browser refresh.


这篇关于防止用户多次单击提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆