Reputation: 21
I have HTML code like this:
<asp:LinkButton ID="AddButton" runat="server" OnClick="AddPatientBtn_Click">
<span class="Normal">Add</span>
</asp:LinkButton>
I find if we click 'Add' several times, it will add several patient records, so I want to change the code like this:
<asp:LinkButton ID="AddButton" runat="server" OnClick="AddPatientBtn_Click" OnClientClick="return DisableButton(this)">
<span class="Normal">Add</span>
</asp:LinkButton>
js:
function DisableButton(button) {
document.all("AddButton").click;
button.href = "javascript:void(0);";
button.setAttribute("disabled", "disabled");
}
But this doesn't work; I can still add many patient records.
What should I do?
Upvotes: 1
Views: 1887
Reputation: 21
Thanks for all of you!
I find that LinkButton may not have the disable attribute, it is a <a>
in html page.
so I use another solution
<asp:LinkButton ID="AddButton" runat="server" OnClick="AddPatientBtn_Click" OnClientClick="return DisableButton()">
<span class="Normal">Add</span>
</asp:LinkButton>
js:
var pending = false;
function DisableButton() {if (pending) {
alert("The new patient is being created. Please wait...");
return false;
}
else {
if (Page_ClientValidate(""))
pending = true;
return true;
}
}
Upvotes: 1
Reputation: 845
var button = document.getElementById("AddButton"); button.setAttribute("disabled", "true");
Upvotes: 0
Reputation: 15112
You can just say
AddButton.Enabled = false;
in the code behind page
or you can write
document.getElementById("AddButton").disabled = true;
Upvotes: 0