Async Calls using ASP.NET 2.0 Client Callback won't work properly if the OnComplete function makes another Client Callback<p><font face="Tahoma,Helvetica,Sans-Serif" size=2>Ref: </font><a title="http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=270828&amp;SiteID=1" href="http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=270828&amp;SiteID=1"><font face="Tahoma,Helvetica,Sans-Serif" size=2>http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=270828&amp;SiteID=1</font></a></p> <p><font face="Tahoma,Helvetica,Sans-Serif" size=2>If you make an asynchronous callback using ASP.NET 2.0 client callback and the OnComplete function you defined makes another callback then you will exeperience unwanted behavior. Here is how it gets started...</font></p> <p><font face=Tahoma size=2>[code lang=&quot;javascript&quot;]<br><font face="Courier New, Courier, Monospace"> <div class=codeseg> <div class=codecontent> <div class=codesniptitle><font style="width:100%">Code Snippet</font></div> <p><font face=Tahoma size=2><font face="Courier New, Courier, Monospace">function StartFirstCallback() {<br>   <font color="#008000">// execute first callback. you get this script from Page.ClientScript.GetCallbackEventReference</font><br></font></font><font face="Courier New, Courier, Monospace"><font size=2><strong>   WebForm_DoCallback('__Page', &quot;&quot;, OnFirstCallbackComplete, null, null, true);</strong><br></font><font size=2>}</font></font></p> <p><font face="Courier New, Courier, Monospace" size=2>function OntFirstCallbackComplete(result, context) {<br></font><font face="Courier New, Courier, Monospace"><font size=2><font color="#0000ff"><font color="#000000">  alert(&quot;First Callback Complete&quot;);</font><br>   </font><font color="#008000">// execute second callback. you get this script from Page.ClientScript.GetCallbackEventReference</font><br><strong>   WebForm_DoCallback('__Page', &quot;&quot;, OnSecondCallbackComplete, null, null, true);</strong><br></font><font size=2>}</font></font></p> <p><font face="Courier New, Courier, Monospace" size=2>function OnSecondCallbackComplete(result, context) {<br>  alert(&quot;Second Callback Complete&quot;);<br></font><font face=Tahoma size=2><font face="Courier New, Courier, Monospace">}</font><br></font></p></div></div> <p> </p></font></font> <p><font face=Tahoma size=2>[/code]</font></p> <p><font face=Tahoma size=2>When you execute the StartFirstCallback function, you will see many alert winows showing &quot;First Callback Complete&quot; and &quot;Second Callback Complete&quot; messages. The reason for this lies in a minor bug in &quot;WebForm_CallbackComplete&quot; function of inbuilt ASP.NET function. Here is the function extracted using Reflector:</font></p> <p><font face="Courier New, Courier, Monospace" size=2>[code lang=&quot;javascript&quot;]<br> <div class=codeseg> <div class=codecontent> <div class=codesniptitle><font style="width:100%">Code Snippet</font></div>function WebForm_CallbackComplete() {<br>    for (i = 0; i &lt; __pendingCallbacks.length; i++) {<br>        callbackObject = __pendingCallbacks[ i ];<br>        if (callbackObject &amp;&amp; callbackObject.xmlRequest &amp;&amp; (callbackObject.xmlRequest.readyState == 4)) {<br>            <strong><em>WebForm_ExecuteCallback(callbackObject);<br></em></strong>            if (!__pendingCallbacks[ i ].async) {<br>                __synchronousCallBackIndex = -1;<br>            }<br>            __pendingCallbacks[ i ] = null;<br>            var callbackFrameID = &quot;__CALLBACKFRAME&quot; + i;<br>            var xmlRequestFrame = document.getElementById(callbackFrameID);<br>            if (xmlRequestFrame) {<br>                xmlRequestFrame.parentNode.removeChild(xmlRequestFrame);<br>            }<br>        }<br>    }<br>}<br></div></div> <p> </p>[/code]</font> <p></p> <p><font face=Tahoma size=2>The bug is due to the point at which the WebForm_ExecuteCallback function gets invoked. This function is responsible to invoke the OnComplete function. But the &quot;__pendingCallbacks&quot; &quot;global&quot; array is updated only after executing the OnComplete function. Note that &quot;__pendingCallbacks&quot; global array is also used inside &quot;<strong>WebForm_DoCallback</strong>&quot; function to add new requests. The following piece of code is extracted from WebForm_DoCallback function:</font></p> <p><font face=Tahoma size=2>[code lang=&quot;javascript&quot;]<br><font face="Courier New, Courier, Monospace"> <div class=codeseg> <div class=codecontent> <div class=codesniptitle><font style="width:100%">Code Snippet</font></div><font face="Courier New, Courier, Monospace">function WebForm_DoCallback(...) {<br> ...<br> ...<br>    var callback = new Object();<br>    callback.eventCallback = eventCallback;<br>    callback.context = context;<br>    callback.errorCallback = errorCallback;<br>    callback.async = useAsync;<br><em><strong>    var callbackIndex = WebForm_FillFirstAvailableSlot(__pendingCallbacks, callback);<br></strong></em> ...<br> ...<br>}<br></font></div></div> <p> </p></font>[/code]</font> <p></p> <p><font face=Tahoma size=2>Here is what happens when the StartFirstCallback function is invoked for the first time:</font></p> <p><font face=Tahoma size=2>1. WebForm_DoCallback is called<br>2. __pendingCallbacks is updated by adding this new request (from step 1). __pendingCallbacks.length = 1<br>3. Callback completes and WebForm_CallbackComplete is called. <br>4. <font color="#993366">[inside WebForm_CallbackComplete]:</font> walks the __pendingCallbacks array (which has one element) and executes the OnComplete function viz. OnFirstCallbackComplete.<br>5. <font color="#993366">[inside OnFirstCallbackComplete]</font>: &quot;First Callback Complete&quot; message is shown. Another async callback requested (OnComplete = OnSecondCallbackComplete)<br>5.1 <font color="#666699">[inside WebForm_DoCallback]</font>: __pendingCallbacks is updated by adding this new request (from step 1). __pendingCallbacks.length = 2.<br><br>Now by the time __pendingCallbacks array is updated inside WebForm_CallbackComplete function at step 4, the async operation completes so quickly that WebForm_CallbackComplete is invoked again for second call (made at Step 5). <u>Here the __pendingCallbacks has 2 elements and most importantly the 0th element is still available (because &quot;<font face="Courier New">__pendingCallbacks[ i ] = null&quot;</font></u><font face="Tahoma,Helvetica,Sans-Serif"><u> statement is still not executed for the very first call) which means the OnStartFirstCallbackComplete function is called again</u>. This starts a kind of infinite calls and only delayed response can stop this.</font></font></p> <p><font face=Tahoma size=2>FIX:<br>Fixing this requires just moving the WebForm_ExecuteCallback statement as the last statement in WebForm_CallbackComplete routine. This ensures that __pendingCallbacks global array is updated before the OnComplete function gets invoked. Here is the updated version.</font></p> <p><font face=Tahoma size=2>[code lang=&quot;javascript&quot;]</font></p><font color="#0000ff" size=1> <p><font face="Courier New, Courier, Monospace" size=2> <div class=codeseg> <div class=codecontent> <div class=codesniptitle><font style="width:100%">Code Snippet</font></div><font face="Courier New, Courier, Monospace" size=2>function</font></font><font face="Courier New, Courier, Monospace" size=2> WebForm_CallbackComplete_SyncFixed() {<br></font><font color="#008000"><font face="Courier New, Courier, Monospace" size=2>  // SyncFix: the original version uses &quot;i&quot; as global thereby resulting in javascript errors when &quot;i&quot; is used elsewhere in consuming pages<br></font></font><font size=2><font face="Courier New, Courier, Monospace"><font color="#0000ff">  for</font> (<font color="#0000ff">var</font> i = 0; i &lt; __pendingCallbacks.length; i++) {<br></font></font><font face="Courier New, Courier, Monospace" size=2>   callbackObject = __pendingCallbacks[ i ];<br></font><font size=2><font face="Courier New, Courier, Monospace"><font color="#0000ff">  if</font> (callbackObject &amp;&amp; callbackObject.xmlRequest &amp;&amp; (callbackObject.xmlRequest.readyState == 4)) {<br></font></font><font color="#008000"><font face="Courier New, Courier, Monospace" size=2>   // the callback should be executed after releasing all resources <br></font></font><font color="#008000"><font face="Courier New, Courier, Monospace" size=2>   // associated with this request. <br></font></font><font color="#008000"><font face="Courier New, Courier, Monospace" size=2>   // Originally if the callback gets executed here and the callback <br></font></font><font color="#008000"><font face="Courier New, Courier, Monospace" size=2>   // routine makes another ASP.NET ajax request then the pending slots and<br></font></font><font color="#008000"><font face="Courier New, Courier, Monospace" size=2>   // pending callbacks array gets messed up since the slot is not released<br></font></font><font color="#008000"><font face="Courier New, Courier, Monospace" size=2>   // before the next ASP.NET request comes.<br></font></font><font color="#008000"><font face="Courier New, Courier, Monospace" size=2>   // FIX: This statement has been moved below<br></font></font><font color="#008000"><font face="Courier New, Courier, Monospace" size=2>   // WebForm_ExecuteCallback(callbackObject);<br></font></font><font size=2><font face="Courier New, Courier, Monospace"><font color="#0000ff">   if</font> (!__pendingCallbacks[ i ].async) {<br></font></font><font face="Courier New, Courier, Monospace" size=2>     __synchronousCallBackIndex = -1;<br></font><font face="Courier New, Courier, Monospace" size=2>   }<br></font><font face="Courier New, Courier, Monospace" size=2>   __pendingCallbacks[i] = <font color="#0000ff">null</font>;<br><br></font><font size=2><font face="Courier New, Courier, Monospace"><font color="#0000ff">   var</font> callbackFrameID = <font color="#800000">&quot;__CALLBACKFRAME&quot;</font> + i;<br></font></font><font size=2><font face="Courier New, Courier, Monospace"><font color="#0000ff">   var</font> xmlRequestFrame = document.getElementById(callbackFrameID);<br></font></font><font size=2><font face="Courier New, Courier, Monospace"><font color="#0000ff">   if</font> (xmlRequestFrame) {<br></font></font><font face="Courier New, Courier, Monospace" size=2>     xmlRequestFrame.parentNode.removeChild(xmlRequestFrame);<br></font><font face="Courier New, Courier, Monospace" size=2>   }<br><br></font><font color="#008000"><font face="Courier New, Courier, Monospace" size=2>   // SyncFix: the following statement has been moved down from above;<br></font></font><font face="Courier New, Courier, Monospace" size=2>   WebForm_ExecuteCallback(callbackObject);<br></font><font face="Courier New, Courier, Monospace" size=2>  }<br></font><font face="Courier New, Courier, Monospace" size=2> }<br></font><font face="Courier New, Courier, Monospace" size=2>}</font></div></div> <p> </p></font></font><font face="Courier New, Courier, Monospace" size=2></font> <p></p> <p><font face=Tahoma size=2>[/code]</font></p> <p><font face="Courier New" size=2></font> </p> <p><font face=Tahoma size=2>Lastly, in order to make sure this function is called instead of original version, the following statement should be executed as startup script.</font></p> <p><font face=Tahoma><font size=2>[code lang=&quot;javascript&quot;]<br><font face="Courier New, Courier, Monospace"><font color="#0000ff"> <div class=codeseg> <div class=codecontent> <div class=codesniptitle><font style="width:100%">Code Snippet</font></div><font size=2><font face="Courier New, Courier, Monospace"><font color="#0000ff">if</font> (<font color="#0000ff">typeof</font> (WebForm_CallbackComplete) == <font color="#800000">&quot;function&quot;</font>) {<br>  <font color="#008000">// set the original version with fixed version<br></font></font></font><font face="Courier New, Courier, Monospace" size=2>  WebForm_CallbackComplete = WebForm_CallbackComplete_SyncFixed;<br></font><font size=2><font face="Courier New, Courier, Monospace">}<br></font></font></div></div> <p> </p></font></font></font><font size=2><font face="Courier New, Courier, Monospace"></font>[/code]</font></font> <p></p> <p><font face=Tahoma size=2>Thanks to Reflector. Can you imagine living without it?</font></p> <p><font face=Tahoma size=2></font> </p> <p><font face=Tahoma size=2></font> </p>© 2009 Microsoft Corporation. All rights reserved.Wed, 19 Aug 2009 14:26:42 Z6c4db554-539a-4b5e-9c0c-e1c41eed4fbbhttp://social.msdn.microsoft.com/Forums/en-US/netfxjscript/thread/6c4db554-539a-4b5e-9c0c-e1c41eed4fbb#6c4db554-539a-4b5e-9c0c-e1c41eed4fbbhttp://social.msdn.microsoft.com/Forums/en-US/netfxjscript/thread/6c4db554-539a-4b5e-9c0c-e1c41eed4fbb#6c4db554-539a-4b5e-9c0c-e1c41eed4fbbBadri Narayananhttp://social.msdn.microsoft.com/Profile/en-US/?user=Badri%20NarayananAsync Calls using ASP.NET 2.0 Client Callback won't work properly if the OnComplete function makes another Client Callback<p><font face="Tahoma,Helvetica,Sans-Serif" size=2>Ref: </font><a title="http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=270828&amp;SiteID=1" href="http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=270828&amp;SiteID=1"><font face="Tahoma,Helvetica,Sans-Serif" size=2>http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=270828&amp;SiteID=1</font></a></p> <p><font face="Tahoma,Helvetica,Sans-Serif" size=2>If you make an asynchronous callback using ASP.NET 2.0 client callback and the OnComplete function you defined makes another callback then you will exeperience unwanted behavior. Here is how it gets started...</font></p> <p><font face=Tahoma size=2>[code lang=&quot;javascript&quot;]<br><font face="Courier New, Courier, Monospace"> <div class=codeseg> <div class=codecontent> <div class=codesniptitle><font style="width:100%">Code Snippet</font></div> <p><font face=Tahoma size=2><font face="Courier New, Courier, Monospace">function StartFirstCallback() {<br>   <font color="#008000">// execute first callback. you get this script from Page.ClientScript.GetCallbackEventReference</font><br></font></font><font face="Courier New, Courier, Monospace"><font size=2><strong>   WebForm_DoCallback('__Page', &quot;&quot;, OnFirstCallbackComplete, null, null, true);</strong><br></font><font size=2>}</font></font></p> <p><font face="Courier New, Courier, Monospace" size=2>function OntFirstCallbackComplete(result, context) {<br></font><font face="Courier New, Courier, Monospace"><font size=2><font color="#0000ff"><font color="#000000">  alert(&quot;First Callback Complete&quot;);</font><br>   </font><font color="#008000">// execute second callback. you get this script from Page.ClientScript.GetCallbackEventReference</font><br><strong>   WebForm_DoCallback('__Page', &quot;&quot;, OnSecondCallbackComplete, null, null, true);</strong><br></font><font size=2>}</font></font></p> <p><font face="Courier New, Courier, Monospace" size=2>function OnSecondCallbackComplete(result, context) {<br>  alert(&quot;Second Callback Complete&quot;);<br></font><font face=Tahoma size=2><font face="Courier New, Courier, Monospace">}</font><br></font></p></div></div> <p> </p></font></font> <p><font face=Tahoma size=2>[/code]</font></p> <p><font face=Tahoma size=2>When you execute the StartFirstCallback function, you will see many alert winows showing &quot;First Callback Complete&quot; and &quot;Second Callback Complete&quot; messages. The reason for this lies in a minor bug in &quot;WebForm_CallbackComplete&quot; function of inbuilt ASP.NET function. Here is the function extracted using Reflector:</font></p> <p><font face="Courier New, Courier, Monospace" size=2>[code lang=&quot;javascript&quot;]<br> <div class=codeseg> <div class=codecontent> <div class=codesniptitle><font style="width:100%">Code Snippet</font></div>function WebForm_CallbackComplete() {<br>    for (i = 0; i &lt; __pendingCallbacks.length; i++) {<br>        callbackObject = __pendingCallbacks[ i ];<br>        if (callbackObject &amp;&amp; callbackObject.xmlRequest &amp;&amp; (callbackObject.xmlRequest.readyState == 4)) {<br>            <strong><em>WebForm_ExecuteCallback(callbackObject);<br></em></strong>            if (!__pendingCallbacks[ i ].async) {<br>                __synchronousCallBackIndex = -1;<br>            }<br>            __pendingCallbacks[ i ] = null;<br>            var callbackFrameID = &quot;__CALLBACKFRAME&quot; + i;<br>            var xmlRequestFrame = document.getElementById(callbackFrameID);<br>            if (xmlRequestFrame) {<br>                xmlRequestFrame.parentNode.removeChild(xmlRequestFrame);<br>            }<br>        }<br>    }<br>}<br></div></div> <p> </p>[/code]</font> <p></p> <p><font face=Tahoma size=2>The bug is due to the point at which the WebForm_ExecuteCallback function gets invoked. This function is responsible to invoke the OnComplete function. But the &quot;__pendingCallbacks&quot; &quot;global&quot; array is updated only after executing the OnComplete function. Note that &quot;__pendingCallbacks&quot; global array is also used inside &quot;<strong>WebForm_DoCallback</strong>&quot; function to add new requests. The following piece of code is extracted from WebForm_DoCallback function:</font></p> <p><font face=Tahoma size=2>[code lang=&quot;javascript&quot;]<br><font face="Courier New, Courier, Monospace"> <div class=codeseg> <div class=codecontent> <div class=codesniptitle><font style="width:100%">Code Snippet</font></div><font face="Courier New, Courier, Monospace">function WebForm_DoCallback(...) {<br> ...<br> ...<br>    var callback = new Object();<br>    callback.eventCallback = eventCallback;<br>    callback.context = context;<br>    callback.errorCallback = errorCallback;<br>    callback.async = useAsync;<br><em><strong>    var callbackIndex = WebForm_FillFirstAvailableSlot(__pendingCallbacks, callback);<br></strong></em> ...<br> ...<br>}<br></font></div></div> <p> </p></font>[/code]</font> <p></p> <p><font face=Tahoma size=2>Here is what happens when the StartFirstCallback function is invoked for the first time:</font></p> <p><font face=Tahoma size=2>1. WebForm_DoCallback is called<br>2. __pendingCallbacks is updated by adding this new request (from step 1). __pendingCallbacks.length = 1<br>3. Callback completes and WebForm_CallbackComplete is called. <br>4. <font color="#993366">[inside WebForm_CallbackComplete]:</font> walks the __pendingCallbacks array (which has one element) and executes the OnComplete function viz. OnFirstCallbackComplete.<br>5. <font color="#993366">[inside OnFirstCallbackComplete]</font>: &quot;First Callback Complete&quot; message is shown. Another async callback requested (OnComplete = OnSecondCallbackComplete)<br>5.1 <font color="#666699">[inside WebForm_DoCallback]</font>: __pendingCallbacks is updated by adding this new request (from step 1). __pendingCallbacks.length = 2.<br><br>Now by the time __pendingCallbacks array is updated inside WebForm_CallbackComplete function at step 4, the async operation completes so quickly that WebForm_CallbackComplete is invoked again for second call (made at Step 5). <u>Here the __pendingCallbacks has 2 elements and most importantly the 0th element is still available (because &quot;<font face="Courier New">__pendingCallbacks[ i ] = null&quot;</font></u><font face="Tahoma,Helvetica,Sans-Serif"><u> statement is still not executed for the very first call) which means the OnStartFirstCallbackComplete function is called again</u>. This starts a kind of infinite calls and only delayed response can stop this.</font></font></p> <p><font face=Tahoma size=2>FIX:<br>Fixing this requires just moving the WebForm_ExecuteCallback statement as the last statement in WebForm_CallbackComplete routine. This ensures that __pendingCallbacks global array is updated before the OnComplete function gets invoked. Here is the updated version.</font></p> <p><font face=Tahoma size=2>[code lang=&quot;javascript&quot;]</font></p><font color="#0000ff" size=1> <p><font face="Courier New, Courier, Monospace" size=2> <div class=codeseg> <div class=codecontent> <div class=codesniptitle><font style="width:100%">Code Snippet</font></div><font face="Courier New, Courier, Monospace" size=2>function</font></font><font face="Courier New, Courier, Monospace" size=2> WebForm_CallbackComplete_SyncFixed() {<br></font><font color="#008000"><font face="Courier New, Courier, Monospace" size=2>  // SyncFix: the original version uses &quot;i&quot; as global thereby resulting in javascript errors when &quot;i&quot; is used elsewhere in consuming pages<br></font></font><font size=2><font face="Courier New, Courier, Monospace"><font color="#0000ff">  for</font> (<font color="#0000ff">var</font> i = 0; i &lt; __pendingCallbacks.length; i++) {<br></font></font><font face="Courier New, Courier, Monospace" size=2>   callbackObject = __pendingCallbacks[ i ];<br></font><font size=2><font face="Courier New, Courier, Monospace"><font color="#0000ff">  if</font> (callbackObject &amp;&amp; callbackObject.xmlRequest &amp;&amp; (callbackObject.xmlRequest.readyState == 4)) {<br></font></font><font color="#008000"><font face="Courier New, Courier, Monospace" size=2>   // the callback should be executed after releasing all resources <br></font></font><font color="#008000"><font face="Courier New, Courier, Monospace" size=2>   // associated with this request. <br></font></font><font color="#008000"><font face="Courier New, Courier, Monospace" size=2>   // Originally if the callback gets executed here and the callback <br></font></font><font color="#008000"><font face="Courier New, Courier, Monospace" size=2>   // routine makes another ASP.NET ajax request then the pending slots and<br></font></font><font color="#008000"><font face="Courier New, Courier, Monospace" size=2>   // pending callbacks array gets messed up since the slot is not released<br></font></font><font color="#008000"><font face="Courier New, Courier, Monospace" size=2>   // before the next ASP.NET request comes.<br></font></font><font color="#008000"><font face="Courier New, Courier, Monospace" size=2>   // FIX: This statement has been moved below<br></font></font><font color="#008000"><font face="Courier New, Courier, Monospace" size=2>   // WebForm_ExecuteCallback(callbackObject);<br></font></font><font size=2><font face="Courier New, Courier, Monospace"><font color="#0000ff">   if</font> (!__pendingCallbacks[ i ].async) {<br></font></font><font face="Courier New, Courier, Monospace" size=2>     __synchronousCallBackIndex = -1;<br></font><font face="Courier New, Courier, Monospace" size=2>   }<br></font><font face="Courier New, Courier, Monospace" size=2>   __pendingCallbacks[i] = <font color="#0000ff">null</font>;<br><br></font><font size=2><font face="Courier New, Courier, Monospace"><font color="#0000ff">   var</font> callbackFrameID = <font color="#800000">&quot;__CALLBACKFRAME&quot;</font> + i;<br></font></font><font size=2><font face="Courier New, Courier, Monospace"><font color="#0000ff">   var</font> xmlRequestFrame = document.getElementById(callbackFrameID);<br></font></font><font size=2><font face="Courier New, Courier, Monospace"><font color="#0000ff">   if</font> (xmlRequestFrame) {<br></font></font><font face="Courier New, Courier, Monospace" size=2>     xmlRequestFrame.parentNode.removeChild(xmlRequestFrame);<br></font><font face="Courier New, Courier, Monospace" size=2>   }<br><br></font><font color="#008000"><font face="Courier New, Courier, Monospace" size=2>   // SyncFix: the following statement has been moved down from above;<br></font></font><font face="Courier New, Courier, Monospace" size=2>   WebForm_ExecuteCallback(callbackObject);<br></font><font face="Courier New, Courier, Monospace" size=2>  }<br></font><font face="Courier New, Courier, Monospace" size=2> }<br></font><font face="Courier New, Courier, Monospace" size=2>}</font></div></div> <p> </p></font></font><font face="Courier New, Courier, Monospace" size=2></font> <p></p> <p><font face=Tahoma size=2>[/code]</font></p> <p><font face="Courier New" size=2></font> </p> <p><font face=Tahoma size=2>Lastly, in order to make sure this function is called instead of original version, the following statement should be executed as startup script.</font></p> <p><font face=Tahoma><font size=2>[code lang=&quot;javascript&quot;]<br><font face="Courier New, Courier, Monospace"><font color="#0000ff"> <div class=codeseg> <div class=codecontent> <div class=codesniptitle><font style="width:100%">Code Snippet</font></div><font size=2><font face="Courier New, Courier, Monospace"><font color="#0000ff">if</font> (<font color="#0000ff">typeof</font> (WebForm_CallbackComplete) == <font color="#800000">&quot;function&quot;</font>) {<br>  <font color="#008000">// set the original version with fixed version<br></font></font></font><font face="Courier New, Courier, Monospace" size=2>  WebForm_CallbackComplete = WebForm_CallbackComplete_SyncFixed;<br></font><font size=2><font face="Courier New, Courier, Monospace">}<br></font></font></div></div> <p> </p></font></font></font><font size=2><font face="Courier New, Courier, Monospace"></font>[/code]</font></font> <p></p> <p><font face=Tahoma size=2>Thanks to Reflector. Can you imagine living without it?</font></p> <p><font face=Tahoma size=2></font> </p> <p><font face=Tahoma size=2></font> </p>Thu, 07 Sep 2006 09:39:01 Z2008-09-04T09:27:57Zhttp://social.msdn.microsoft.com/Forums/en-US/netfxjscript/thread/6c4db554-539a-4b5e-9c0c-e1c41eed4fbb#42ca5249-e285-4e9d-a358-0d94767d9b64http://social.msdn.microsoft.com/Forums/en-US/netfxjscript/thread/6c4db554-539a-4b5e-9c0c-e1c41eed4fbb#42ca5249-e285-4e9d-a358-0d94767d9b64Dan Randolphhttp://social.msdn.microsoft.com/Profile/en-US/?user=Dan%20RandolphAsync Calls using ASP.NET 2.0 Client Callback won't work properly if the OnComplete function makes another Client CallbackGood post except the&nbsp;['i'] subscript for __pendingCallbacks was replaced by the 'idea' image everywhere in your post. I would also point out that you can get to this source code using the VS Script debugger in VS 2005. You can find it in the WebResource.axd file&nbsp;under the page using the callbacks in the Script Explorer tab.Wed, 06 Dec 2006 02:09:11 Z2006-12-06T02:09:11Zhttp://social.msdn.microsoft.com/Forums/en-US/netfxjscript/thread/6c4db554-539a-4b5e-9c0c-e1c41eed4fbb#507a0489-0136-478f-b535-b792efc7ebd9http://social.msdn.microsoft.com/Forums/en-US/netfxjscript/thread/6c4db554-539a-4b5e-9c0c-e1c41eed4fbb#507a0489-0136-478f-b535-b792efc7ebd9Nenad Vicentichttp://social.msdn.microsoft.com/Profile/en-US/?user=Nenad%20VicenticAsync Calls using ASP.NET 2.0 Client Callback won't work properly if the OnComplete function makes another Client Callback<p>This is most impresive fix I ever saw!!!</p> <p>Tested, work. I hade 2 overlapping callbacks and this solved issue.</p> <p> </p> <p>As already said, only to take care on copy-paste to put back indexer i instead of those 3 bulbs.</p> <p> </p> <p>Awesome.</p>Sat, 19 May 2007 17:14:50 Z2007-05-19T17:14:50Zhttp://social.msdn.microsoft.com/Forums/en-US/netfxjscript/thread/6c4db554-539a-4b5e-9c0c-e1c41eed4fbb#ba4494ad-dc26-41ec-a77a-fd2778d3476ahttp://social.msdn.microsoft.com/Forums/en-US/netfxjscript/thread/6c4db554-539a-4b5e-9c0c-e1c41eed4fbb#ba4494ad-dc26-41ec-a77a-fd2778d3476abrmhttp://social.msdn.microsoft.com/Profile/en-US/?user=brmAsync Calls using ASP.NET 2.0 Client Callback won't work properly if the OnComplete function makes another Client CallbackThanks so much for the post. It really saved me! I just added the function to the script called in my startup and prior to calling WebForm_DoCallback added the &quot;if (typeof...&quot; statement. Thanks again!!Fri, 15 Jun 2007 20:07:06 Z2007-06-15T20:07:06Zhttp://social.msdn.microsoft.com/Forums/en-US/netfxjscript/thread/6c4db554-539a-4b5e-9c0c-e1c41eed4fbb#6c4ad109-4afc-4cab-9939-291c4794e59fhttp://social.msdn.microsoft.com/Forums/en-US/netfxjscript/thread/6c4db554-539a-4b5e-9c0c-e1c41eed4fbb#6c4ad109-4afc-4cab-9939-291c4794e59ftournevicehttp://social.msdn.microsoft.com/Profile/en-US/?user=tourneviceAsync Calls using ASP.NET 2.0 Client Callback won't work properly if the OnComplete function makes another Client CallbackHi guys!<br><br>I've implemented this function on my aspx page, but I get an error automatically when I want to save some data in my DB.<br><br>Here is the error :<br><br><span class="objectBox objectBox-errorMessage hasBreakSwitch opened">&quot;__pendingCallbacks is not defined&quot;<br><br>I've got an input button which invoke the callback function. But, when the callback finish, javascript throw me this error...<br><br>I don't find anything about this on the web. So if you know how to resolve this, that would be great! <img alt=Smile src="http://forums.microsoft.com/MSDN/emoticons/emotion-1.gif"><br><br>Here is the save button code (nothing magic):<br><br>function CallBackSave() {<br>        var arg = 'sa';<br>        var context = new Object();<br>        &lt;%=RefClientFuncInitiatingCallBack %&gt;<br>    }<br><br>And the sync function has not been modified.<br><br>Thx!<br></span>Fri, 31 Aug 2007 09:08:16 Z2007-08-31T09:08:16Zhttp://social.msdn.microsoft.com/Forums/en-US/netfxjscript/thread/6c4db554-539a-4b5e-9c0c-e1c41eed4fbb#3544c75c-cc75-4cb8-be87-52c688622f17http://social.msdn.microsoft.com/Forums/en-US/netfxjscript/thread/6c4db554-539a-4b5e-9c0c-e1c41eed4fbb#3544c75c-cc75-4cb8-be87-52c688622f17Nenad Vicentichttp://social.msdn.microsoft.com/Profile/en-US/?user=Nenad%20VicenticAsync Calls using ASP.NET 2.0 Client Callback won't work properly if the OnComplete function makes another Client Callback<p>My guess is that you probably missed indexer somewhere:</p><font size=2> <p align=left> <div class=codeseg> <div class=codecontent> <div class=codesniptitle><span style="width:100%">Code Snippet</span></div>__pendingCallbacks[i] <p align=left> </p></div></div> <p align=left> </p> <p></p></font> <p align=left><font face=Arial size=2>instead, you probably put just:</font><font size=2></p> <div class=codeseg> <div class=codecontent> <div class=codesniptitle><span style="width:100%">Code Snippet</span></div> <p align=left>__pendingCallbacks</p> <p align=left> </p></div></div> <p align=left> </p></font> <p></p>Fri, 31 Aug 2007 10:30:18 Z2007-08-31T10:30:18Zhttp://social.msdn.microsoft.com/Forums/en-US/netfxjscript/thread/6c4db554-539a-4b5e-9c0c-e1c41eed4fbb#42f43c8a-f44f-4383-ac0e-abd901dc5a82http://social.msdn.microsoft.com/Forums/en-US/netfxjscript/thread/6c4db554-539a-4b5e-9c0c-e1c41eed4fbb#42f43c8a-f44f-4383-ac0e-abd901dc5a82Manav Guptahttp://social.msdn.microsoft.com/Profile/en-US/?user=Manav%20GuptaAsync Calls using ASP.NET 2.0 Client Callback won't work properly if the OnComplete function makes another Client CallbackHi Badri,<br><br>Its a very helpful post. It solved few issues on my website that I was not able to figure out and there were no javascript error messages for help.<br><br>Thanks again for such a helpful solution.<br><br>MG<br>Fri, 31 Aug 2007 23:36:57 Z2007-08-31T23:36:57Zhttp://social.msdn.microsoft.com/Forums/en-US/netfxjscript/thread/6c4db554-539a-4b5e-9c0c-e1c41eed4fbb#77ee8536-9d35-4439-bc18-2fb9e08de76dhttp://social.msdn.microsoft.com/Forums/en-US/netfxjscript/thread/6c4db554-539a-4b5e-9c0c-e1c41eed4fbb#77ee8536-9d35-4439-bc18-2fb9e08de76dhoobastankerhttp://social.msdn.microsoft.com/Profile/en-US/?user=hoobastankerAsync Calls using ASP.NET 2.0 Client Callback won't work properly if the OnComplete function makes another Client Callback<p>Badri,</p> <p>This post is fantastic and solved a problem that I've been having for quite a while.  My specific instance was especially weird - I was only calling CallServer a second time if the user clicked 'Yes' on a javascript confirm message.  But the behaviour until I found your fix was the opposite, the code behind was only initiated if the user clicked 'Cancel' on the confirm message - if the user clicked 'Yes', the infinite loop became obvious.  <br/><br/>Thank you very much for taking the time to post this - I dropped it into my aspx page and it worked straight away :)</p>Wed, 19 Aug 2009 14:26:12 Z2009-08-19T14:26:12Z