Help! JS error thrown when AJAX scripts are dynamically loaded for newly visible control.

Last post 04-01-2009 9:49 AM by Danny117. 4 replies.

Sort Posts:

  • Help! JS error thrown when AJAX scripts are dynamically loaded for newly visible control.

    03-31-2009, 2:54 PM
    • Contributor
      5,904 point Contributor
    • atconway
    • Member since 09-24-2007, 9:20 PM
    • Florida U.S.A
    • Posts 1,234

    (I think this is going to take a wiz to understand, but please give it a try; 10 points to the expert!!)

    Background:  I have an ASP.NET AJAX web app that can be launched from our external Sharepoint portal accessable to employees of our company via the internet.  Traditionally, when the site is run from inside the company the url to the default page is as follows:

    http://MyASPNetApp/Pages/Default.aspx

    ...when accessed via the SharePoint portal, the site is passed as a query string from the main portal's site address as follows:

    https://www.ourcompanyportal.com/Pages/,DanaInfo=MyASPNetApp+Default.aspx

    The 'DanaInfo=' is added everywhere including if veiwing the source on a page that includes AJAX.  Traditionally, the script reference in the page's source would be as follows:

    script src="/ScriptResource.axd?d=-tCmVI5qDJ3yI-BH1oZD2Xgv_m6oCh7y6d3mVAu8Ih2bYq0LoRRLRi2zKYMtHvVX9FMzUcK6-j2wNZMFGbKeNCposW6tctq5yr3dOBAqDwc1&t=ffffffffd2c7995f" mce_src="/ScriptResource.axd?d=-tCmVI5qDJ3yI-BH1oZD2Xgv_m6oCh7y6d3mVAu8Ih2bYq0LoRRLRi2zKYMtHvVX9FMzUcK6-j2wNZMFGbKeNCposW6tctq5yr3dOBAqDwc1&t=ffffffffd2c7995f" type="text/javascript"
     
     This same source pulled up via the site that was pulled up through our Sharepoint portal is as follows:
    script src="/,DanaInfo=MyASPNetApp,CT=js+ScriptResource.axd?d=DG6RXWoKNh76Nda17-e1arV9TyMEFuIfMEy7nnLdGGR464jQbDCnNP3yjAnping2mXRm3ra2cVBIEsNGLPMm9G3TcJvZnbX5QwHEdeHrzEs1&t=ffffffffd2c7995f" mce_src="/,DanaInfo=MyASPNetApp,CT=js+ScriptResource.axd?d=DG6RXWoKNh76Nda17-e1arV9TyMEFuIfMEy7nnLdGGR464jQbDCnNP3yjAnping2mXRm3ra2cVBIEsNGLPMm9G3TcJvZnbX5QwHEdeHrzEs1&t=ffffffffd2c7995f" type="text/javascript"
    
    
      
     Notice in order for the site pulled up via SharePoint the 'DanaInfo' is appended on to everyhting so the proper location can be resolved.  This method works about 99% of the time; it is not a manual process just something Sharepoint automatically does.

    However, I found today that if I have an ASP.NET page that contains AJAX in a hidden control (say a grid) that is not initially visible, and then made visible by a user action (button click, whatever), then the additional AJAX scripts are dynamically loaded at that time when the control becomes visible.

    This is actually pretty efficient and I like it.  The problem is that the dynamically loaded AJAX scripts from the newly visable control DO NOT have the appropriate 'DanaInfo' preappnded modifiers added to them and a JavaScript error is thrown as follows:

    Error: Sys.ScriptLoadFailedException: The script ‘/ScriptResource.axd?d=Cfo4m…………could not be loaded.

    I am able to verify that the scripts are dynamically loaded after the page loads in the 'Solution Explorer' window in VS.NET 2008 while debugging.  (Note:  In IE the checkbox for "Disable Script Debugging - Internet Explorer" must be unchecked to see the 'Script Documents' node in VS.NET's Solution Explorer).  While debugging I can see the many AJAX scripts being loded under the 'Script Documents' node in the Solution Explorer as I navigate to pages.  Upon making the control visible on my page, I can see additional AJAX scripts loaded for the AJAX controls that were previously hidden.

    So there it is.  Those dynamically loaded AJAX scripts for the newly visible control containing AJAX is causing my site to throw an JavaScript error because it can not load the script because it does not know where it is.  Again, this is not a problem when just ran through the traditional site link; it has to do with being pulled up via the Sharepoint portal.

    Does anyone know a way around this issue?  Is there any way maybe serverside to force loading ALL of the AJAX scripts needed, even for controls that are hidden upon Page_Load?  I think if something like this is possible then it may solve this problem, or if there are any other solutions please speak up!!

    Yes

    Thank you,   >[Blog]<

    "The best thing about a boolean is even if you are wrong, you are only off by a bit." :D
    -anonymous

  • Re: Help! JS error thrown when AJAX scripts are dynamically loaded for newly visible control.

    03-31-2009, 8:22 PM
    • Star
      10,558 point Star
    • Danny117
    • Member since 12-16-2008, 9:30 AM
    • Royal Oak Michigan USA
    • Posts 1,837

    I'm actually the Supreme Comander so I should be able to help.

    This is a lot of work but you can do it.  Download the scripts rename them and save them on your web site.  Use the scriptprofiler (didn't work for meEvil Empire Script Reference Profiler

     

    Good Luck



  • Re: Help! JS error thrown when AJAX scripts are dynamically loaded for newly visible control.

    04-01-2009, 9:03 AM
    • Contributor
      5,904 point Contributor
    • atconway
    • Member since 09-24-2007, 9:20 PM
    • Florida U.S.A
    • Posts 1,234

    I had downloaded the ScriptProfiler and slapped it on a page to see which scripts were being used.  Unfortunantly it only shows the scripts used that it can see upon page load (I think it is stripping it out of the source or something). It would not show the additional scripts needed after a control was made visible; the list from the profiler never refreshes.  I could also verify this because I have some grids with ValidatorCallouts, and the profiler never mentioned them being used.  It only shows the ones used with active controls on Page_Load.

    I was able to get around this by just temporarily placing extra AJAX controls (the same ones that are hidden initially) on the page just to get the script reference.

    I think I compiled a list off all of the AJAX scripts used throughout the application.  I then wanted to use the new <CompositeScript> functionality of the Script Manager in the .NET Framework 3.5 to go ahead and combine all of those scripts ahead of time.  Right now I was more concerned with having the app work rather than the extra overhead in combining scripts that may not be used right away.  My ScriptManager exsists in the MasterPage, so I wanted to combine all needed scripts to make them avaliable right away.

    Unfortunantly, I got the following message:

    The resource URL cannot be longer than 1024 characters. If using a CompositeScriptReference, reduce the number of ScriptReferences it contains, or combine them into a single static file and set the Path property to the location of it.

    I don't know if this script combining will even work, but it seems like pre-loading the ones needed into 1 script that is downloaded from the MasterPage upon opening the app should work, right?

    Now you were suggesting that I actually download the scripts and have them locally in my project that is deployed correct?  I have (2) questions about this:

    1.  How do I download the AJAX scripts needed?

    2.  How do I then point my application to use the local scripts, as opposed to the ones installed on the server?

     

    Thank you,   >[Blog]<

    "The best thing about a boolean is even if you are wrong, you are only off by a bit." :D
    -anonymous

  • Re: Help! JS error thrown when AJAX scripts are dynamically loaded for newly visible control.

    04-01-2009, 9:19 AM
    • Contributor
      5,904 point Contributor
    • atconway
    • Member since 09-24-2007, 9:20 PM
    • Florida U.S.A
    • Posts 1,234

    One other quick question! Big Smile

    It will not bother me that when my site is pulled up externally that the UpdatePanels don't work as intended and the pages must fully post back rather than having partial page postbacks.  It is not ideal, but this app is probably used 10% externally and 90% internally (as intended to be used anyways), so if full postbacks are required and solve the isssue - no big deal.

    I thought initially it was an all or nothing deal; strip out all Update Panels on pages that unhide controls or leave them on there.  I found the following attribute can be applied 1 time either at runtime or at design time that will disable partial page postbacks and forces all pages (without changing exsisting AJAX) to have full post backs:

    EnablePartialRendering="false"

     What I am thinking, is if I could determine some way from extracting the URL or something that my site was being called from an external link, then I could programatically set the above property to sort of "shut down" the features that are causing this issue.  I just tested it and it seems that all update panels are disabled.

    Can you add thoughts to this, or if this is an ok solution?

    Thank you,   >[Blog]<

    "The best thing about a boolean is even if you are wrong, you are only off by a bit." :D
    -anonymous

  • Re: Help! JS error thrown when AJAX scripts are dynamically loaded for newly visible control.

    04-01-2009, 9:49 AM
    Answer
    • Star
      10,558 point Star
    • Danny117
    • Member since 12-16-2008, 9:30 AM
    • Royal Oak Michigan USA
    • Posts 1,837

    Here's another method.

    Ajaxcontrol toolkit you can use the ScriptPath attribute on the extenders and load the scripts that way.  Download the script source for the toolkit.

     

     

    Good Luck



Page 1 of 1 (5 items)