简体   繁体   中英

Disabling multiple button for multiple click issue in ASP.Net

I have 2 Buttons

<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();" />

On page load i am disabling those 2 if clicked (for multiple click issue)

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

Now i want to disable both buttons even if i have clicked one button. how do i achieve this?

Client Side:

<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>

Server Side: on Page Load

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

I notice you have also mentioned another function "return validation()" in mark ups. if you are using asp.net webforms validations. I think whatever the scripts required for validations get added automatically after your custom scripts in the rendered html.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM