ASP.NET防止双击 [英] ASP.NET prevent double clicking

查看:127
本文介绍了ASP.NET防止双击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我之前已经看过它,发现当我对其进行测试时,适用于Google Chrome,Firefox和IE的javascript可以使用,但是它似乎是随机的(或特定于浏览器的)它不起作用.我需要一个可行的解决方案.

I've looked at this before and found javascript that works for me with Google Chrome, Firefox, and IE when I test it but it seems randomly (or browser specific) it doesn't work. I need a solution that does work.

这是我目前在jQuery中使用的:

This is what I'm currently using with jQuery:

$(document).ready(function () {
    $("a.Once").one("click", function () {
        $(this).click(function () { return false; });
    });
});

我将"Once"类添加到要确保不会多次单击的按钮上.再说一次,它始终对我来说正常工作,但对于某些用户它什么也没做.是否有更好的替代解决方案始终有效?

I add the class "Once" to buttons I want to make sure aren't clicked more than once. Again, It always works properly for me but for some users it doesn't do anything at all. Is there a better alternative solution that always works?

更新:这些是ASP.NET链接按钮.

Update: These are ASP.NET LinkButtons.

更新6/18: 我从两个不断遇到此问题的用户那里获得了更多信息.

Update 6/18: I've gotten more info from two users who keeps having this problem.

有人说他按下按钮一次,屏幕闪烁,因此他离开页面并回到页面并再次按下按钮,这导致该页面自动发布两次.

One says he hits the button once and the screen flashes so he leaves the page and comes back to it and hits the button again which causes it to post twice automatically.

其他人声称他按下了另一个按钮,这导致该按钮自动回发两次.我查看了代码,该按钮没有任何问题.

The other claims he hits a different button which causes this button to postback twice automatically. I looked at the code and there's nothing wrong with that button.

我唯一想到的是缓存问题,或者在页面完成加载之前按一下按钮.我一直无法重现该问题,其中一个正在使用与我使用的浏览器完全相同的浏览器.

The only thing I can think of is a caching problem or maybe hitting the button before the page finishes loading. I haven't been able to reproduce the problem and one of them is using the exact same browser I use.

推荐答案

如果这是用于表单发布,则可以使用以下命令禁用所有提交按钮:

If this is for a form post, then you can disable all submit buttons on submit with:



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

还是允许他们多次单击,但只能在一段时间后单击?

Or are they allowed to click more than once, but only after some time has elapsed?

在某些情况下,one()会失败-请参阅注释 http://api.jquery.com/one/ 知道您的用户的浏览器兼容性问题或jQuery无法加载吗?

There are scenarios where one() fails - see the comments on http://api.jquery.com/one/ Any idea if its a browser compat issue with your users or jQuery not loading?

刚刚发现这是一个链接按钮.在这种情况下,请尝试

Just found out this is a linkbutton. in that case try



$('#yourClientIdForYourLinkButton').click(function(e) {
    e.preventDefault();
});

或直接使用clientid之类的

or using the clientid directly something like



$('#<%=linkButton.ClientId%>').click(function(e) {
    e.preventDefault();
});

这篇关于ASP.NET防止双击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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