Home / AJAX

HOW TO Load a Custom Script

RSS
Modified on 2009/12/04 17:23 by Stephen Walther Categorized as Uncategorized
The Script Loader can be used to load any required ASP.NET Ajax Library scripts or jQuery scripts using Sys.require. It can also be used to load custom scripts by using Sys.loadScripts. Although the <script> element can certainly be used to load custom scripts, by using the Script Loader your application can take advantage of parallel script loading which can speed up a page's load time.

To load one or more custom scripts a call can be made to Sys.loadScripts which accepts an array of scripts to load, a function to call once the scripts have been loaded, and a user context object that can be used to track state. An example of using Sys.loadScripts to load two scripts named Rules.js and Calculations.js is shown next:
<script src="/Scripts/Start.js" type="text/javascript"></script>

<script type="text/javascript">

Sys.loadScripts(["../Scripts/Rules.js", "../Scripts/Calculations.js"], function() { var result = Add(2, 2); var valid = Validate(); if (valid) alert(result); });

</script>