[英]Disabling a button doesn't fire click event on server side
I have an imagebutton in my aspx page like: 我的aspx页面中有一个图像按钮,如:
<asp:ImageButton ID="btnProcessPayment" ImageUrl="~/Images/process-payment.png" OnClientClick="return disableButton(this);"
runat="server" OnClick="btnProcessPayment_Click" />
This is my javascript function: 这是我的javascript函数:
function disableButton(button) {
button.disabled = true;
return true;
}
As you can see in my javascript event handler I have disabled the button to prevent the user from click the button twice. 正如您在我的javascript事件处理程序中看到的那样,我已禁用该按钮以防止用户单击该按钮两次。 However, even my server side event handler doesn't get fired due to this.
但是,即使我的服务器端事件处理程序也不会因此而被触发。 What am I doing wrong?
我究竟做错了什么?
Note: If I comment out this line button.disabled = true;
注意:如果我注释掉这一行
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;
}
You need to fire out serverside event of the button some thing like this 你需要点击按钮的服务器端事件这样的事情
onclick="this.disabled=true;__doPostBack('buttonclientid','');"
or 要么
function disableButton(button) {
button.disabled = true;
__doPostBack('buttonclientid','');
return true;
}
Use this and it worked for me 使用它,它对我有用
__doPostBack('<%= btnSubmit.ClientID %>', '');
where btnSubmit
is the ID of my button and I wanted to trigger the server side click event for the button. 其中
btnSubmit
是我的按钮的ID,我想触发按钮的服务器端单击事件。 It works. 有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.