Articles → ASP .NET AJAX → Sys.Loader.Definescript And Sys.Require Method In Asp.Net Ajax

Sys.Loader.Definescript And Sys.Require Method In Asp.Net Ajax






Purpose







Syntax


Sys.loader.defineScript({
    name: "",
    releaseUrl: "",
    dependencies: [""],
    isLoaded: !!()
});




  1. name – This property provides unique name to the script.
  2. releaseUrl – This property defines the path of the script file.
  3. dependencies – This property defines the dependency of the script file (if any).
  4. isLoaded – This property checks if the script file gets loaded or not.
  5. Sys.require(Script_name);





Example


<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
   <head runat="server">
      <title></title>
      <script src="http://code.jquery.com/jquery-latest.js" type="text/javascript"></script>
      <script src="http://ajax.microsoft.com/ajax/beta/0911/Start.js"></script>
   </head>
   <body>
      <form id="form1" runat="server">
         <asp:ScriptManager runat="server" EnableCdn="True"></asp:ScriptManager>
         <a href="#">Click Me</a>
      </form>
      <script type="text/javascript">
         try {
             Sys.loader.defineScript({
                 name: "MyLibrary",
                 releaseUrl: "/test.js",
                 dependencies: ["jQuery"],
                 isLoaded: !!(window.TestMethod)
             });
         
             Sys.require(Sys.scripts.MyLibrary);
         } catch (e) {
             alert(e);
         }
         $(document).ready(
             function () {
                 $("a").click(
                     function () {
                         try {
                             TestMethod();
                             
                         } catch (e) {
                             alert(e);
                         }
                     });
             });
      </script>
   </body>
</html>




function TestMethod() {
    alert("Test");
}



Output


Picture showing the output of Sys.loader.defineScript and Sys.require method in asp.net ajax
Click to Enlarge


Posted By  -  Karan Gupta
 
Posted On  -  Friday, September 7, 2018

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250