禁用按钮不会触发点击服务器端事件 [英] Disabling a button doesn't fire click event on server side

查看:177
本文介绍了禁用按钮不会触发点击服务器端事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ImageButton的在我的aspx页面,如:

I have an imagebutton in my aspx page like:

<asp:ImageButton ID="btnProcessPayment" ImageUrl="~/Images/process-payment.png" OnClientClick="return disableButton(this);"
                                    runat="server" OnClick="btnProcessPayment_Click" />

这是我的javascript函数:

This is my javascript function:

function disableButton(button) {
            button.disabled = true;
            return true;
        }

你可以在我的JavaScript事件处理看,我已经禁用了按钮,以防止从用户点击两次按钮。然而,即使我的服务器端事件处理程序没有得到应有这种解雇。我在做什么错

As you can see in my javascript event handler I have disabled the button to prevent the user from click the button twice. However, even my server side event handler doesn't get fired due to this. What am I doing wrong?

注意:如果我注释掉这一行 button.disabled = TRUE; 一切运作得非常好。

Note: If I comment out this line button.disabled = true; all works out pretty well.

推荐答案

禁用按钮禁用表单提交也是如此。你需要做的提交自己:

Disabling the button disables the form submit as well. You need to do the submit yourself:

function disableButton(button) { 
    button.disabled = true; 
    __doPostBack(<%= btnProcessPayment.ClientID %>,'');   // need to manually submit
    return true; 
} 



更新按的 Waqas 的建议!

这篇关于禁用按钮不会触发点击服务器端事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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