javascript confirmation dialog box
I have a page with a button and when it is clicked, it will execute a long time task asynchronously. I tried to implement validation on that button using javascript and a confirmation dialog box will pop up when it is clicked. But when i clicked on 'Cancel' in the confirmation dialog box, the long time task still will be executed instead of returning false.
Any idea guys? Any help is appreciated!
Code-Behind:
btnPrint.Attributes.Add("onclick"开发者_开发问答, "javascript:submittingID='btnAdd';return validation();")
Public Sub LongTimeTask()
.......
End Sub
Javascript:
function validation() {
....
confirmPrint()
}
function confirmPrint() {
if (confirm("Are you sure you want to print? This process may take up to few minutes.") == true)
return true;
else
return false;
}
validation
doesn't return anything. try:
function validation() {
//...
return confirmPrint();
}
You can also remove the if from confirmPrint
. Doesn't change the behavior, but no need to check for true and return true:
function confirmPrint() {
return confirm("Are you sure you want to print?");
}
My guess from the description you gave is something like this:
<a href="javascript:if(confirm('Do you want to run this long task?')){ longTask() };">Link Text</a>
精彩评论