1

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
0

1 Answer 1

6

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.