我的asp.net
页面上有一个交易按钮。
如果用户点击交易按钮,该按钮应该被禁用,直到交易结束。
如何使用客户端脚本来完成?
可以,假设您的事务是 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;
};
}
按钮代码:
<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;
}
客户端脚本 -
OnClientClick= "this.disabled = true; this.value = 'Submitting...'; enableImage();"
UseSubmitBehavior="false" Text="确认订单" onclick="BtnSubmit_Click1" />