问题
I am using a DevExpress ASPxButton on a webpage of mine, and need a way to stop the user from being able to double click the button. My initial thought was to try:
function OnClick(s, e) {
s.SetEnabled(false);
e.processOnServer;
}
Unfortunately, I found out DevExpress stops all server side events from firing when you disable a button. So I went ahead and did some googling and ended up on the DevExpress website (which can be infuriatingly unhelpful sometimes) which gave an official "work around" which they reference in the other help threads on their site regarding this issue. Here is the link for reference.
for anyone unwilling to click the link, they recommended this:
var buttonClicked = false;
function MyBtnClick(s,e){
if(buttonClicked) return;
buttonClicked = true;
// do something
}
which I turned into:
var buttonClicked = false;
function OnClick(s, e) {
if (buttonClicked) return;
buttonClicked = true;
e.processOnServer;
}
At first I thought this was working, but then realized it worked for a double click, but if the user were to click a third time, it just went ahead and processed again. For what should be an easy task, I seem to be having a hard time with this one (granted I am relatively new to JavaScript, so maybe the answer is obvious). If anyone knows of a way to disable the button after the first click while still allowing it to process on the server the first time, it would be appreciated.
回答1:
I searched for some options for your issue, if you can check the links below :
http://www.devexpress.com/Support/Center/Question/Details/Q438771
http://www.devexpress.com/Support/Center/Question/Details/Q273711
http://www.devexpress.com/Support/Center/Question/Details/B132082
回答2:
There is easy way how you can accomplish it. On the click event you need to wrap the button table.
function SaveButtonClick(s,e) {
// Disable Save button in order not to click twice
$("#" + s.uniqueID).wrap("<span style='pointer-even: none; opacity: 0.5;'> </span>");
if (ValidationSummary) {
e.processOnServer = true;
}
else {
e.processOnServer = false;
// Enable Save button
$("#" + s.uniqueID).unwrap();
}
}
This is the easiest way I think.
来源:https://stackoverflow.com/questions/24919882/need-workaround-for-setenabledfalse-stopping-e-processonserver-with-devexpress