Javascript error - 'Array' is undefined RRS feed

  • Question

  • User706013099 posted

    I have an intermittent problem that I think is related to use of the Ajax Control Toolkit. Incidentally this is a non-public website running on ASP.NET 4.0 which is only required to support IE10+ browsers.

    I have a fairly simple page containing one GridView linked to an ObjectDataSource with Select and FilterParameters. There is also an ImageButton with an ID of AddButton with an attached ModalPopupExtender as follows:

    <ajaxToolkit:ModalPopupExtender ID="MPE" runat="server" TargetControlID="AddButton" PopupControlID="AddPanel" BackgroundCssClass="modalBackground" DropShadow="true"
                OkControlID="CloseButton" OnOkScript="javascript:void window.location.assign('polform.aspx');" CancelControlID="CancelButton" />
    <asp:Panel ID="AddPanel" runat="server" style="display:none" >
      <iframe id="AddFrame" runat="server" width="717" height="370" style="background:transparent;border:none;margin:0;padding:0;" />
    <div style="display:none">
      <asp:Button ID="CloseButton" ClientIDMode="Static" runat="server"/>
      <asp:Button ID="CancelButton" ClientIDMode="Static" runat="server"/>

    I set the src of the iframe in code behind on Page.Load as follows (the url can only be determined programmatically):

    If Not IsPostBack Then
                If Roles.IsUserInRole("Editor") Then
                    AddFrame.Attributes("src") = "addpol.aspx?id=" & .....
                    AddButton.Visible = True
                    AddButton.Visible = False
                End If
            End If

    The modal popup itself works fine when the button is clicked. But even when the button is not clicked, I get an intermittent fatal Javascript error in the parent page when there is a seemingly unrelated postback - such as an AutoPostBack on a TextBox used for a filter, paging on the GridView or even a simple link to a separate page. But 9 times out of 10 (not a precise measure!) there is no error and everything is fine. The error has not so far occurred when the initialisation code on Page.Load is not run, so I assume that it must in some way be related to setting the iframe src, but I cannot see why this code would itself involve Javascript without the button even being clicked.

    The Javascript error as reported by VS2012 is something like 'Array' is undefined, but I have no idea what this is referring to. I suspect that it may be a timing issue related to scripts not being loaded or something, but I do not know how to go about investigating this.

    I am several versions behind the latest version of the Toolkit (I have so far tested with the January 2013 release 7.0123 and the June 2013 release 7.0607), but I have not found any reported workitems which appear to relate to my problem so am reluctant to upgrade to a newer version unless I am confident that this is a known issue that has been resolved. Has anyone else experienced anything similar or have any suggestions as to how best to investigate such an issue? Is there a better way/place/time to initialise the iframe or otherwise ensure that all dependencies are fully loaded?


    Thursday, February 20, 2014 1:12 PM

All replies

  • User-933407369 posted

    Hi jstranger, 

    Sorry , i don't reproduce your issue again.

    At first you need to make sure that the 'Array' is what you use in the javascript function.  View source to make sure that you are using the right ClientID. i think that your page exists Javascript error  which is related to the elements of document.

     i would suggest you try debugging your javascript codes in Internet Explorer,put debug point(Break Point) here , run in debug mode, after pressing F5, press F10 to check the for loop.

    you also can check out the links :



    Hope it helps you.

    Friday, February 21, 2014 3:13 AM
  • User706013099 posted

    I do not have any Javascript function other than the OnOkScript on the ModalPopupExtender as in my original post. And if I view source there is no reference to an object called 'Array' anywhere in the page.

    Friday, February 21, 2014 4:15 AM
  • User706013099 posted

    And apart from the ModalPopupExtender the parent page is otherwise extremely simple - there is no ValidationSummary and no use of UpdatePanel. Just an ObjectDataSource a couple of TextBox and DropDownList controls and a GridView.

    Friday, February 21, 2014 4:18 AM
  • User-933407369 posted

    Could you provide  a simple demo which is related to this issue? It may be a bit easier to resolve if it can be easily reproduced.
    Thank you for your understanding.

    Monday, February 24, 2014 5:52 AM
  • User706013099 posted

    Thanks for the reply. Since my last post I was in fact working on trying to discover the simplest page that would reproduce the error. As a starting point I made a copy of the failing page and ran that within the same website/project/solution - and I have not been able to get it to fail! Same code, same master page, same stylesheet, same bin folder (including the Ajax Control Toolkit). In both cases running from VS 2012 Express in debug mode using IIS Express on the same Windows 7 PC. But if I run the original page I can pretty much guarantee the Javascript error on any postback in around 1 in 5 attempts. The only difference that I can think of is that I renamed the copy of the page, but that is clearly not the issue as I have had the same error with other similar pages. So currently I cannot provide a simple demo that will reproduce the error. And I am out of ideas other than to recreate the failing pages and hop for the best.

    Monday, February 24, 2014 10:59 AM
  • User-933407369 posted

    if so , you can update the last version of AjaxControlToolKit:

    PM> Install-package AjaxControlToolKit

    then recreate the project and rebuild the project.

    I hope you can succeed as far as soon.

    Tuesday, February 25, 2014 3:48 AM
  • User706013099 posted

    I really do not want to update to a later version of the Toolkit right now unless I really have to - there have been far too many reported bugs and problems with the last few releases.

    But in any case, why would 2 identical pages, each running against the same version of the Toolkit, have different behaviour? And having done some further investigation, it is even more baffling. Yesterday the copy of the page which did not produce errors was in a different folder to the one that was failing. I have just now placed a copy of the page which did not produce errors and placed in in the same folder as the failing page - and sure enough it produces the same errors! But I have also had the same error with pages in a separate web app, so it is not just an issue with this folder. Is there some way that a particular combination of pages in a folder could be an issue?

    Tuesday, February 25, 2014 5:03 AM
  • User706013099 posted

    It appears that the cause of the Javascript error was due to some sort of clash between the page producing the error (which I will call the parent) and the modal popup page which is loaded into an iframe (which I will call the child). I had forgotten that when I put a copy of the parent page in a different folder and got no error, there was actually a difference between that scenario and the original failing scenario - i.e. there was no child page in that folder.  Hence when I set the iframe src in code behind, nothing was actually loaded (I had assumed that the child page was not loaded until the button was clicked to show the modal popup, but this is clearly not the case). The likely reason for the error was the fact that I had a ToolkitScriptManager in both the master page for the parent page and that for the child page (by chance with the same ID). Prior to implementing the ModalPopupExtender/iframe approach, I had opened my popups using a simple Javascript window.open. Hence the parent and the child were completely separate and there was no clash. However, in the case of an iframe, I guess this is no longer the case. Anyway, I have for now removed the ToolkitScriptManager from the child's master page and have not encountered the error since. But (assuming that I have now resolved the issue) why this scenario should cause an intermittent error before the child page is actually run is difficult to comprehend.

    Tuesday, February 25, 2014 8:48 AM
  • User555306248 posted

    Have you tried using the Developer Tools (F12) within your browser and checking the Console area to see if any particular errors are present? 

    Tuesday, February 25, 2014 10:36 PM
  • User706013099 posted

    Since my last post, needless to say, the problem has not completely gone away after I removed the ToolkitScriptManager from my child page - although it is now much less frequent (roughly 1 in 20 postbacks to the page raise the error rather than the 1 in 5 previously) - possibly because the child page is simpler. I still believe that it is some 'clash' (for want of a better term) between the parent page and the child page when the latter is running in an iframe, as I never had this problem previously when I used to load essentially the same child page from essentially the same parent page using window.open. I must admit to not having had much experience with iframes, so would welcome any observations others may have on potential issues with this approach. I am fairly certain that the error does not occur if the iframe src is not set in code behind (which I can test very easily simply by not logging in) or if the child page is missing. And I can get the error without clicking on the button to open the modal popup, whereas clicking on the button and running the child page does work. So I do not now think it has anything to do with the ModalPopupExtender and I have been trying to identify other elements in either page which might generate Javascript. I do have a CKEditor 4 control in my child page, which will clearly do so. Is it possible that running CKEditor in a page in an iframe is unstable, even before the page is actually active?

    One potential workaround that occurs to me is not to set the iframe src until the click of the button that opens the modal popup. I did actually try this originally but was doing so server-side which I guess will not work. Presumably I could set the OnClientClick property of the button to do the same thing in Javascript, but would this interfere with the working of the ModalPopupExtender (I guess the amswer is to try it)?

    I have tried using the IE F12 tools, but haven't yet managed to get the error in that mode. Might that be significant? And if I do get a console message, will it give me more information than the VS2012 reported error?

    Wednesday, February 26, 2014 9:08 AM