简体   繁体   English

将ASP.NET Webforms OnClick事件限制为一次

[英]Limiting ASP.NET webforms OnClick event to one time

I have a Web forms button like this which serves to complete the order that user has made on the website using paypal: 我有一个这样的Web表单按钮,用于完成用户使用Paypal在网站上所做的订单:

<asp:Button style="padding-left:10px !important;" ID="Button1" runat="server" OnClick="Button1_Click" Text="Complete order" />

Once the button is clicked... the data of the order gets stored inside the DB. 单击按钮后,订单数据将存储在数据库中。 Now my problem is, what if the user triggers the event multiple times at once (for no reason lets say)... If they do that.. I'll get multiple errors... So my question here is how do I limit the user to only be able to trigger the on click event just once... Next time he/she tries to click it, the event won't be triggered? 现在我的问题是,如果用户一次触发事件多次(无缘无故地说)...如果他们这样做,那么我会遇到多个错误...所以我的问题是如何限制用户只能触发一次onclick事件...下次他/她尝试单击该事件时,不会触发该事件吗? Is there any handy way to do this via Server/Client side programming? 通过服务器/客户端编程有什么方便的方法吗? Perhaps via Javascript?? 也许通过JavaScript?

You can do this client side with JQuery via " one " 您可以通过“ 一个 ”使用JQuery进行此客户端

$('#SomeForm').one('submit', function() {
    $(this).find('input[type="submit"]').attr('disabled','disabled');
});

That will only let the button be clicked once. 那只会让按钮被点击一次。 You shoudln't rely on this for payment scenarios tho. 您不应该依赖此作为付款方案。 You can tag something into Session["Clicked"] = true; 您可以在Session["Clicked"] = true;标记一些内容Session["Clicked"] = true; or similar to make sure that it only gets processed once server side. 或类似的内容,以确保仅在服务器端处理一次。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM