Page view counter

First callback works, second callback gets error

Last post 02-26-2006 4:14 PM by codequest. 2 replies.

Sort Posts:

  • First callback works, second callback gets error

    02-24-2006, 3:19 PM
    • Loading...
    • codequest
    • Joined on 10-30-2005, 2:55 PM
    • Posts 461
    • Points 2,127

    The code below represents a "2 round" callback test bench.  It does one callback, and then another one.   It completes both callbacks.  However, in the second round, it produces the following exception:

    ------------------------------------------------------------------
    line 164
    char 13
    Error:  '__pendingCallbacks[...].async' is null or not an object
    URL:  (stuff) ................/CallBackTest.aspx
    ------------------------------------------------------------------

    I got a similar error in the full app when I did only one round of callback, which I traced to a variable declaration/scope issue ( %-} javascript newbie..).   When I got the same type of error in the "two rounds" of callback, I looked for a similar issue, but did not find it (which doesn't mean it isn't there...)   So I tried to replicate it in this test bed, assuming it would work here OK, where there are no mis-declared variables (perhaps a rash assumption...)  But the error does occur here, and since the test code is pretty bare (and can be made more bare), I'm out of ideas.

    I've included a test procedure below.  I just tested it all the way through and it works and produces the error.  Takes literally only a few minutes to setup....

    I would appreciate any suggestions on how to fix this problem, so that I can use these callback techniques in the full app.

    Thanks!

    ======================  TEST PROCEDURE  =============================

    >  Create a new web site (I'm using VS2005)
    >  Delete the Default page
    >  Add a Webform named "CallBackTest" with VB code behind
    >  Add a Class named "G"
    >  Add a Javascript file named JScript
    >  Copy the code sections below (to the appropriate files) to completely replace the contents of four files just added (code behind = 4th file)
    >  Compile it with debug
    >  select from the drop down and click the button

    Alerts show the activity moving through the code.
    The error occurs near the end, as the code is executing or returning from the second round callback

    =====================   THE WEBFORM =====================================


    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="CallBackTest.aspx.vb" Inherits="CallBackTest" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>Untitled Page</title>
    </head>
    <body style="font-family:Sans-Serif;font-size:medium">
    <script src=JScript.js></script>
    <script>

    function StartCallBack(varMessage) {
      alert("at start of callback client sender")
      var Command = varMessage
      var context = new Object();                                                   
      context.CommandName = "StartCallBack";
      <%=CallBackSenderSetupString%>
    }

    function CallBackHandler(varCallBackResult, varContext) {              
        alert("at start of callback client receiver")
      if (varContext.CommandName == "StartCallBack" ) {            
        CallBackRouter(varCallBackResult) }
      }
       
    function onError(message, context) {              
     alert("Exception :\n" + message);               
    }

    </script>
        <form id="form1" runat="server">
        <div>     
            <select id="Select1" style="z-index: 107; left: 44px; position: absolute; top: 60px">
            <option>ADD</option>
            <option>MOVE</option>
            </select>
           
            <input id="TestButton" style="z-index: 104; left: 36px; position: absolute; top: 96px"
                type="button" value="button" language="javascript" onclick="TestButton_onclick()" />
            &nbsp;&nbsp;
          
            <input id="Text2" style="z-index: 106; left: 40px; position: absolute; top: 132px; width: 484px;"
                type="text" />
            &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;
        </div> 
        </form>
    </body>
    </html>


    =====================   THE CLASS FILE  =====================================


    Imports Microsoft.VisualBasic

    Public Class G
        Public Shared CBString As String

        Public Shared Sub CallBackRouter(ByVal varString)

            If varString = "ADD" Then
                CBString = "$CMD$EXTRA$ADD$" & varString & "  From the server router sub"
                Exit Sub
            End If

            If varString = "MOVE" Then
                CBString = "$CMD$EXTRA$MOVE$" & varString & "   From the server router sub"
                Exit Sub
            End If

            If varString = "$ADD$ROUND2" Then
                CBString = "$ADD$ROUND2$RETURN" & "   From the server router sub"
                Exit Sub
            End If

            If varString = "$MOVE$ROUND2" Then
                CBString = "$MOVE$ROUND2$RETURN" & "   From the server router sub"
                Exit Sub
            End If

            CBString = "INVALID REQUEST"

        End Sub
    End Class


    =====================   THE VB CODE BEHIND  FILE =====================================


    Partial Class CallBackTest
        Inherits System.Web.UI.Page
        Implements ICallbackEventHandler

        Public CallBackSenderSetupString As String           '  this is used to communicate with the client

        Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) _
          Handles Me.Load
            '  callbackStr is translated into Javascript
            CallBackSenderSetupString = Page.ClientScript.GetCallbackEventReference(Me, "Command", _
            "CallBackHandler", "context", "onError", False)

        End Sub

        '   This receives information from the client
        Public Sub RaiseCallbackEvent(ByVal eventArgument As String) Implements

    System.Web.UI.ICallbackEventHandler.RaiseCallbackEvent
            '  the eventArgument contains the information from the client "Command" variable
            'MsgBox("I'm in 'RaiseCallbackEvent' at the server")

            G.CallBackRouter(eventArgument)

        End Sub

        '  This returns information to the client
        Public Function GetCallbackResult() As String Implements System.Web.UI.ICallbackEventHandler.GetCallbackResult
            Return G.CBString   'the string has the information from the server side actions
        End Function

    End Class


    =====================   THE JAVASCRIPT  FILE  =====================================


    function TestButton_onclick() {
    var Text1 = document.getElementById("Select1")
    //alert("started")
    var Text2 = document.getElementById("Text2")
    Text2.value = ""
    RunTest(Text1.options[Text1.selectedIndex].text)
     }  

    function RunTest(varString) {
    //alert("calling GetCallBackValue")
    wrkVar = GetCallBackValue(varString)  }

    function GetCallBackValue(varString) {
    alert("initiating callback in GetValue")
    wrkvar = StartCallBack(varString) }

    function CallBackRouter(varString) {
    alert("in the client router")
    if (varString.indexOf("$CMD$EXTRA$ADD") > -1) {DoAddCallBack("$ADD$ROUND2"); return}
    if (varString.indexOf("$CMD$EXTRA$MOVE") > -1) {DoMoveCallBack("$MOVE$ROUND2"); return }

    if (varString.indexOf("$ADD$ROUND2") > -1) {DoAdd(varString); return }
    if (varString.indexOf("$MOVE$ROUND2") > -1) {DoMove(varString); return }
    }

    function DoAddCallBack(varString) {
    var Text2 = document.getElementById("Text2")
    Text2.value = "Starting Second Round"
    alert ("starting round 2 add callback")
    wrkvar = StartCallBack(varString)
    }

    function DoMoveCallBack(varString) {
    var Text2 = document.getElementById("Text2")
    Text2.value = "Starting Second Round"
    alert ("starting round 2 move callback")
    wrkvar = StartCallBack(varString)
    }

    function DoAdd(varString) {
    var Text2 = document.getElementById("Text2")
    Text2.value = ""
    Text2.value = "DO ADD = " + varString }

    function DoMove(varString) {
    var Text2 = document.getElementById("Text2")
    Text2.value = ""
    Text2.value = "DO MOVE = " + varString }

    ==================================================

     

     

  • Re: First callback works, second callback gets error

    02-24-2006, 6:12 PM
    • Loading...
    • codequest
    • Joined on 10-30-2005, 2:55 PM
    • Posts 461
    • Points 2,127

    Probably should have done a search first, but the best answers (as of this date) seem to be here:

    http://west-wind.com/weblog/posts/2694.aspx  (feedback at bottom of page)

    and unfortunately, there really isn't a "how to" answer here that fits this situation (far as I can tell...)

    So, still looking...

  • Re: First callback works, second callback gets error

    02-26-2006, 4:14 PM
    • Loading...
    • codequest
    • Joined on 10-30-2005, 2:55 PM
    • Posts 461
    • Points 2,127

    In review, looking for a way around this, I asked myself why the program should do two call backs with no user intervention in between...and recognized that was not a particularly useful design in the first place!

    So this problem is solved by making that "feature" go away.  Which is a good thing, since it's a known MS bug and there doesn't seem to be a fix right now.   For the situation in which two call backs in quick succession because of, for example, two user clicks, there are some answers in the link above.



     

Page 1 of 1 (3 items)