禁用交易按钮,直到 asp.net 页面中的交易结束



我的asp.net页面上有一个交易按钮。
如果用户点击交易按钮,则应禁用该按钮,直到交易结束。

如何使用客户端脚本完成此操作?

按钮代码:

<asp:Button ID="btnTransaction" runat="server" Text="Submit" onclick="btnTransaction_Click" OnClientClick="DisableMe(this.id);" />

客户端脚本:

<script type="text/javascript">
    function DisableMe(id)
    {
        document.getElementById(id).disabled = true;
    }
</script>

然后在服务器端使用

protected void btnTransaction_Click(object sender, EventArgs e)
    {
        // after your transction code executes
        btnTransaction.Enabled = true;
    }

是的,它可以,假设你的事务是一个 ajax 请求,你可以使用 javascript 执行以下操作:

 performTransaction = function() {
    var btn = document.getElementById('transaction_btn'), ajax;
    btn.disabled = true;
    // perform ajax request....
    ajax = ...;
    ajax.onreadystatechange = function(ste) {
        btn.disabled = false;
    };
}

客户端脚本 -
OnClientClick= "this.disabled = true;this.value = '正在提交...'; enableImage();"
使用提交行为="false" 文本="确认订单" onclick="BtnSubmit_Click1"/>

最新更新