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

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

问题描述

我的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 的建议进行了更新!

Updated as per Waqas suggestion!

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

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