4

I have a VB .net application that I am attempting to integrate with a former deverlopers code. The code takes a zipcode and returns a list of stores, along with their location on a google map canvas.

The process works great, with one exception.

I get the following error

JavaScript runtime error: Accessing the 'caller' property of a function or arguments object is not allowed in strict mode.

I have isolated the culprit to

__doPostBack('userControlSearchResults_results', LatLng);

Which internally has the following

function Sys$WebForms$PageRequestManager$_doPostBack(eventTarget, eventArgument) {
        var event = window.event;
        if (!event) {
            var caller = arguments.callee ? arguments.callee.caller : null;
            if (caller) {
                var recursionLimit = 30;
                while (caller.arguments.callee.caller && --recursionLimit) {
                    caller = caller.arguments.callee.caller; // ERRORS HERE
                }
                event = (recursionLimit && caller.arguments.length) ? caller.arguments[0] : null;
            }
        }
    ...

My first inclination was to create a window.event so it by passes the if(!event) and moves on. Since, there are other times we call __doPostback in the code and it is successful.

However since my JavaScript is limited, i am either doing it wrong or need to find a different approach.

I have searched for this problem and very little has come back. The common response is to just comment out the 'use strict'; and move on.

The problem is we pull in a lot of JavaScript libraries and many of them are now set to 'use strict'

Does anyone have a suggestion or an idea on how to address this?

A blog made reference to trying to apply a setTimeout() before the __doPostback call. However I do not see how that would resolve anything.

Edit: Added some more code.

__doPostback is within the following javascript

function CompleteSearch(returnedLatLng) {

    if (returnedLatLng != '') {
        alert("dopostback here2- this is where it breaks");
        __doPostBack('ucSearchResults_udpResults', returnedLatLng);
        if (document.getElementById("sidebar_search")) { document.getElementById("sidebar_search").style.display = "none" };
        if (document.getElementById("sidebar_login")) { document.getElementById("sidebar_login").style.display = "none" };
        if (document.getElementById("promo1")) { document.getElementById("promo1").style.display = "none" };
        document.getElementById("sidebar_results").style.display = "block";
        //document.getElementById("sidebar_results").style.display = "none";
    }
    return false;
}

Where as my update panel is within a user control and looks like this...

<form id="Form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<div id="Container" style="zoom:1" onclick="">
    <asp:UpdatePanel runat="server" ID="udpResults" OnLoad="UpdatePanel1_Load">
        <ContentTemplate>
            <asp:HiddenField ID="currentLatLong" runat="server" />
            <asp:HiddenField ID="triggerSearch" runat="server" Value="0" />
            <asp:HiddenField ID="searchString" runat="server" Value="0" />

            <asp:HiddenField ID="locationCode" runat="server" />
            <asp:HiddenField ID="locationDesc" runat="server" />
            <asp:HiddenField ID="locationPhone" runat="server" />
            <asp:HiddenField ID="locationZip" runat="server" />

            <asp:HiddenField ID="filterPickup" runat="server" />
            <asp:HiddenField ID="filterVirtualKiosk" runat="server" />
            <asp:HiddenField ID="filterDelivery" runat="server" />
            <asp:HiddenField ID="filterAcceptsCash" runat="server" />
            <asp:HiddenField ID="filterKey2Key" runat="server" />
            <asp:HiddenField ID="filterHODService" runat="server" />

            <asp:Label ID="tblResults" runat="server"></asp:Label>
        </ContentTemplate>
    </asp:UpdatePanel>
</div>
</form>

Does this help or would more code be required. I am really stuck right now and do not know where to proceed.

  • I don't think this __doPostBack javascript code was done by any developer, I think that it's the ASP engine generates it. I think you should post the ASP code, maybe these userControlSearchResults_results function. – xavigonza Apr 23 '14 at 23:39
  • You are correct, the Sys$Web... is generated by the engine. However the line "caller = caller.arguments.callee.caller" is what trips the error. The code works with an older classic ASP website. I am attempting to integrate with a newer site. I will review the __doPostBack process. – shifting winds Apr 24 '14 at 13:54

2 Answers2

2

This problem occurs when window.event contains null.

I found that it contains null on a JavaScript timer event only.
Maybe it contains null on some other special events too.

There are 2 solutions.

Solution A:

1/ on the timer event: rise an user interface element event like click
2/ on an event handler for this element event: call __doPostBack

There is still a trap.
You may think that you can create an event objet and fire it on an element.
This would work, but window.event would still contain null.
It looks strange, but I suppose it is by design.

The only way to trigger an element event AND having window.event containing the event instead of null is to call this element click method.

Solution B:

If the UpdatePanel contains an input type="submit" element, there is no need to call __doPostBack to perform an asynchronous postback.
Calling this element click method is enought.

If the UpdatePanel contains no input submit element, the timer event handler can create one and use it:

var btn = document.createElement('INPUT');  
btn.setAttribute('name', 'timer_dummy_button');  
btn.setAttribute('type', 'submit');  
btn.setAttribute('value', 'what you like');  
btn.setAttribute('style', 'display:none;');  
document.getElementById('yourNiceLittleUpdatePanelID').appendChild(btn);  
btn.click();

On asynchronous postback, Page.Request.Form would contain these items :

["yourNiceLittleScriptManagerControlID"] = "yourNiceLittleUpdatePanelID|timer_dummy_button"  
["__EVENTTARGET"] = ""  
["__EVENTARGUMENT"] = ""  
["timer_dummy_button"] = "what you like"  
figolu
  • 1,388
  • 13
  • 6
0

I don't think this Sys$WebForms$PageRequestManager$_doPostBack javascript code was done by any developer, I think that it's the ASP engine generates it. I think you should post the ASP code, maybe this userControlSearchResults_results function's code.

There are many posts on how to use __doPostBack. Check that you use it properly.

How to use __doPostBack()

Community
  • 1
  • 1
xavigonza
  • 170
  • 1
  • 7