简体   繁体   中英

confirm() cancel button no longer working in IE11

I have an asp.net 4 site that I am using javascript's confirm() method before a user deletes an object from the database as a client based confirmation. With IE6-10, Firefox, Chrome, and Safari this works well. I click on cancel and it stops the page loading. However I been having problems using this on a usercontrol with IE11.

The usercontrol loads a datagrid which has an link button that gets the server to call a delete stored procedure.

With IE11, the Confirm popup opens, but if I click the cancel button or x on the window does not stop the page posting and calling the delete command in the server. I tried everything I can think off, but it just always passes and reads the page as valid.

In the code behind of the ItemDataBound we have this...

DeleteButton.CommandArgument = ac.ID.ToString(); //set the id so we know what to delete
DeleteButton.Attributes.Add("onclick", "Sure(event)");

This attaches the javascript to the image button.

Then in the file that contains the javascript we have the following code...

function Sure(evt){
var ans = confirm("Are you sure you want to delete? \n\nPress OK to continue or Cancel to stop.");
if(!ans){
    var e = (window.event)? window.event:evt;
    e.returnValue = false;
    return false;
}
}

Debugging, it is setting the values to false and returning them when I press the cancel button, but this isn't stopping the postback like every other browser does. It goes straight to the call for the database to delete it.

Any idea why IE11 wouldn't stop the postback after confirm was cancelled?

If I'm hearing you right, don't you mean...?

"onclick", "return Sure(event)"

...

function Sure(evt){
var ans = confirm("Are you sure you want to delete? \n\nPress OK to continue or Cancel to stop.");
if(!ans){
    var e = (window.event)? window.event:evt;
    e.returnValue = false;
    return false;
} else {
return ans;
}
}

From my understanding your script shouldn't work anywhere, even IE11. If you don't "return" the value of the function, you are just executing the function and ignoring the fact the confirm dialog returns "false".

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