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: !!()
});












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



Click to Enlarge

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

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250