在ASP.Net中禁用多个单击问题的多个按钮

时间:2015-10-28 15:16:20

标签: javascript c# asp.net

我有2个按钮

<asp:Button ID="btnSubmit1" Text="Submit"  runat="server"  OnClick="btnSubmit1_Click" OnClientClick="return Validation();" />
<asp:Button ID="btnSubmit2" Text="Submit"  runat="server"  OnClick="btnSubmit2_Click" OnClientClick="return Validation();" />

在页面加载时,我会在单击时禁用这两个(对于多次点击问题)

btnsubmit1.OnClientClick = ClientScript.GetPostBackEventReference(btnsubmit1, "") + "; this.value='Processing...';this.disabled = true;";
btnsubmit2.OnClientClick = ClientScript.GetPostBackEventReference(btnSubmit2, "") + "; this.value='Processing...';this.disabled = true;";

现在我想要禁用两个按钮,即使我点击了一个按钮。我怎么做到这一点?

1 个答案:

答案 0 :(得分:0)

客户端:

<script type="text/javascript">
function disableButtons() {
 var btn1 = document.getElementById("<%=btnSubmit1.ClientID%>");
 var btn2 = document.getElementByID("<%=btnSubmit2.ClientID%>");
 btn1.disabled = true; btn2.disable = true;
}
</script>

服务器端:页面加载

btnsubmit1.OnClientClick = "disableButtons();this.value='Processing...'"
btnsubmit1.OnClientClick = "disableButtons();this.value='Processing...'"

我注意到你还在标记中提到了另一个函数“return validation()”。如果你使用asp.net webforms验证。我认为在渲染的html中自定义脚本之后会自动添加验证所需的脚本。