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: !!()
});
- name – This property provides unique name to the script.
- releaseUrl – This property defines the path of the script file.
- dependencies – This property defines the dependency of the script file (if any).
- isLoaded – This property checks if the script file gets loaded or not.
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