How to call a function after the update progress is completed in an update panel? - panel

I have a button in the update panel. Another function say function1 is executed in the click event of this button. I want to call a javascript function once the function1 completes execution. How will I know when the function1 has completed its execution?

Assuming function1 runs onthe server, and function2 on the client,
handle the endRequest event of the Sys.WebForms.PageRequestManager MSAjax class.

Related

How to trigger the event in AnyLogic and then make it cyclic?

I would like to make the cyclic event. This event periodically calculates some parameters of the model. However, the event should be triggered once by a condition. I have no idea how to do that.
I tried to make the event.reset() at the beginning and then restart it after the appropriate condition is met.
However, I received the errors:" agent cannot be resolved to a variable"
If I delete the reset and restart functions for the event, everything will be ok. The event is cyclic and works fine.
The double click on the error shows the stings where the error is occurred (highlighted with red color):
On model start-up, suspend the event by using:
event.reset();
Once the condition you have is met, use:
event.restart();

Cancel "done" listener to jQuery AJAX Deferred?

If I have an AJAX request I initiated with a jQuery $.ajax() call, and at the time attached a done() listener to, is there a way to un-listen to it? I have a situation with a search-as-you-type field, where if a request gets made to the server that for whatever reason takes a long time to respond, but while waiting the user types a bit more and a second request fires and comes back quickly, when the first request eventually completes, the done() listener fires, rewriting the DOM with the the first request's data, not the second.
I've tried issuing an abort() call on the AJAX, or reject() on the Deferred right before the second request is made, but that shows the error state for the first call while the second call is in-flight.
I tried coming up with an ID system to hash out which request is the "current" one, so in the done() listener it first checks "am I still the most recent request?" before updating the DOM, but that seems clunky that the app needs to create an ID/Hash methodology for each API endpoint?
On every done callback you could log a timestamp, and execute the callback only if the timestamp is the latest one yet. So:
var latest_ts = 0;
$.get('...').done(function() {
var this_ts = (new Date).getTime();
if (this_ts < latest_ts) return;
latest_ts = this_ts;
//callback code here...
});
So if request A is fired but request B is fired after it but returns first, the timestamp is updated and A's callback will be ignored, as its timestamp is out of date.

Press any key in 5 seconds

To clarify, I am using ComputerCraft (emulator: http://gravlann.github.io/, language: Lua)
I know that to wait for a keypress
os.pullEvent("key")
and to wait 5 seconds I need to use this
sleep(5)
but I want to wait for a keypress and disable the event waiter after 5 seconds.
I'm not familiar with ComputerCraft API, but I guess, You could use parallel API for this. Basically, it allows executing two or more functions in parallel.
To be specific - parallel.waitForAny. Which returns after any of function finished, so, only the one being executed. In contrary, parallel.waitForAll waits for all functions being executed.
I'd use something like this:
local action_done = 0
local function wait_for_keypress()
local event, key_code = os.pullEvent("key")
--do something according to separate key codes? :}
end
local function wait_some_time()
sleep(5)
end
action_done = parallel.waitForAny(wait_for_keypress, wait_some_time)
--action done now contains the number of function which was finished first.
EDIT: if using only ComputerCraft API, You should change to this (using timer event):
local function wait_some_time()
os.startTimer(5)
end

Subsequent events not triggering in while loop

I have a MAIN VI and a SUB VI which communicate events through control refnum. flow of events is as follows.
1) sub vi changes a value of its control and this event is handled in the main vi(this works).
2) main vi in response to the event changes one of its control and triggers an event from the event handler itself which is handled in the subvi event handler.(this also works).
The first phase is over. Now the main vi is running a while loop and the sub vi is running a while loop and main vi triggers an event every ~150ms. Which is to be handled in the subvi. This is the part which is not happening. I can see the main vi's control getting updated but the event(if generated) is not handled by the subvi. I'm using control's property node->Value(signalling) to change the value as well as trigger the event. What can be the possible cause?
note: the control (whose value is changed), event handler are the same as in the first phase.
Hope my question is clear.
i found the problem .
the subsequent events were not being handled because the loop in which the event handler ran looped once
i.e the initial condition was itself false so the loop only ran once.
this loop was controlled by stop if true. it had to be continue if true.
the boolean variable that controlled this loop was true. this should have been my first clue.

AJAX periodical check until conditions are met

I have an application which communicates with mobile phone gate. User has to send SMS/Text to number and then needs to wait for confirmation.
I'd like to know how to check for response until user receives it. How can I call AJAX check every 10 seconds?
You can use a spin-off of a long polling technique.
Basically just set a setInterval function that will fire every 10 seconds. The callback function of that will be your ajax call. Make the ajax function check the value of a variable, presumably one that is a boolean representing whether or not the text has been confirmed.
setInterval(function() {
if(!condition) {
//ajax functionality again
}
}, 10*1000);
The reason why I have the !condition part is because I dont want the function to execute all the way if the condition has already come back true, thus confirming the text.
You should then kill the interval function too.

Resources