2

我有一个带有 imageButton 的 Asp.net (Ver4) 网页,用于通过 imagebuttons 单击事件后面的代码将表单数据提交到数据库。在后面的代码中,我使用 response.redirect 将它们移动到感谢页面,它是例程后面代码的最后一行。由于数据库有点慢,有时我想禁用点击事件,直到页面被重定向。我正在尝试用 jquery 来做到这一点。我已经能够禁用该按钮并使其显示为已禁用,但是我背后的代码根本没有触发。

这是我正在使用的 JQuery

function test() {
    $("#ImageButton1").attr("disabled", "disabled").css('opacity',' 0.5');
}

这是按钮的 aspx 代码

<div class="button">
      <asp:ImageButton ID="ImageButton1" runat="server" Height="28px"
           OnClientClick="test();"
           onclick="ImageButton1_Click" 
           ImageUrl="media/finishbutton.jpg" 
           style="margin-top: 0px" Width="97px" />
</div>
4

4 回答 4

2

最简单的解决方案是在点击事件触发后稍后禁用该元素。例如:

 function test() {
    setTimeout(function () { $("#<%=ImageButton1.ClientID %>").attr("disabled", "disabled").css('opacity', ' 0.5'); }, 10);
}
于 2012-08-20T21:29:47.137 回答
1

试试这个:

 function test() {
$("#<%=ImageButton1.ClientID%>").attr("disabled", "disabled").css('opacity',' 0.5');
//$("#ImageButton1").css('opacity', ' 0.5');

}

在 aspx 中

 <div class="button">
          <asp:ImageButton ID="ImageButton1" runat="server" Height="28px" OnClientClick="javascript:test();"
              onclick="ImageButton1_Click" 
              ImageUrl="media/finishbutton.jpg" style="margin-top: 0px" Width="97px" />
        </div>
于 2012-08-20T21:17:51.810 回答
0

尝试在函数return true;末尾添加test()

于 2012-08-20T21:12:35.693 回答
0

您可以添加 beforeAsyncPostBack 并禁用此处描述的按钮,或者仅从单击处理程序返回 true。此外,您可能希望使用 clientID 来禁用按钮,而不仅仅是服务器理解的元素 ID。

于 2012-08-20T21:19:45.777 回答