Can you tell me why this works:
PageMethods.UpdateForcedDisposition(forcedDisposition, a.value, SucceededCallback, FailedCallback);
When this doesn’t?
setTimeout("PageMethods.UpdateForcedDisposition(" + forcedDisposition + "," + a.value + ", SucceededCallback, FailedCallback);", 1000);
Interestingly, a similar call works with setTimeout:
setTimeout("PageMethods.UpdateSales(" + id + ", " + a.value + ", SucceededCallback, FailedCallback);", 1000);
...I’m stumped!
Richard JP Le Guen
28.8k8 gold badges93 silver badges121 bronze badges
asked Nov 8, 2010 at 22:52
user263097
2941 gold badge4 silver badges15 bronze badges
1 Answer 1
Avoid passing a string to setTimeout. Where possible, use anonymous functions:
window.setTimeout(function () {
PageMethods.UpdateForcedDisposition(
forcedDisposition,
a.value,
SucceededCallback,
FailedCallback
);
}, 1000);
A setTimeout with a string executes in the global scope. If you're trying to reference variables from the current scope, you'll hit an error.
answered Nov 8, 2010 at 22:55
Andy E
346k86 gold badges482 silver badges452 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-js