LA.NET [EN]

Nov 07

During beta 1, we could easily load external scripts by adding a <script> element to the page, by using the ClientScriptManager and even by using the ScriptReference element in order to add references to external Javascript files. Beta 2 introduces some changes when you load a script file through a ScriptElement entry. The docs mention this briefly by saying the following:

“Component developers and page developers creating file-based script libraries that are registered
with the ScriptManager control should include a JavaScript code snippet that indicates that the
library has been downloaded by the client. Although this is not required in all browsers,
Safari requires this to be able to dynamically load scripts.”

 

After talking with my good friend Garbin (thanks for pointing me in the right direction) and after running some tests, I”d say that this means is that now we must call the notifyScriptLoaded method exposed by the global Sys.Application object. To test this, let”s build a simple page. We”ll start by defining a Javascript file (test.js):

alert(“howdy! I”m an external file” );
if( Sys && Sys.Application ){
   Sys.Application.notifyScriptloaded();
}

Now, you must have noted the test for Sys and Sys.Application. Well, i”ve put it there since i”m lazy and I”d like to use my libraries in several web apps (which means that it has to run when i have a global Sys.Application object – which allways happens in an AJAX page – and when i don”t). btw, i could have gone further and added a test for the method but, as I said, I”m lazy :,,)

Now, adding the file is really simple, like the following page shows:

<%@ Page Language=”C#” %>
<!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>
  <form id=”form1″ runat=”server”>
      <asp:ScriptManager runat=”server” ID=”manager”>
        <Scripts>
               <asp:ScriptReference Path=”test.js” />
        </Scripts>
     </asp:ScriptManager>
   </form>
</body>
</html>

Nothing to difficult, but still something that must be registered for future use.

13 comments so far

  1. Mitch
    8:01 am - 11-12-2006

    Trying your example produces an odd error error in IE 7. After the alert displays with the message and I hit ok, I drop into test.js in VS 2005 with the breakpoint at Sys.Application.notifyScriptLoaded() – runtime error: object doesn”t support this property or method.

    I check off Disable script debugging in IE and get the Error on page after I dismiss the alert that says: Sys.ScriptLoadFailedException: The script “test.js” could not be loaded or does not contain the Sys.Application.notifyScriptLoaded() callback.

    Do I have something configured incorrectly? Or? Thanks in advance.

    Mitch

  2. ...
    8:31 am - 2-28-2007

    Very nice site! Good work.

  3. ...
    7:03 am - 3-31-2007

    Du musst ein Fachmann sein – wirklich guter Aufstellungsort, den du hast!

  4. ...
    9:17 pm - 4-23-2007
  5. ...
    5:16 pm - 4-24-2007
  6. gonzolder
    1:23 am - 5-9-2007

    ja krevetko! Vsem sasat”!

  7. aarst
    5:28 pm - 5-12-2007

    higuys!What yourblog powered by?

  8. Papayum
    2:41 am - 6-30-2007

    Thank you.

  9. tron
    7:20 pm - 1-10-2008
  10. tron
    6:33 am - 1-11-2008
  11. goro
    6:59 pm - 1-14-2008
  12. DARLAWyatt25
    1:09 am - 10-8-2010

    Don”t have a lot of money to buy a building? Don”t worry, because that”s available to get the personal loans to resolve such problems. Hence get a small business loan to buy all you need.