In my application more pages have got Script Manager in them hence my script which depends on them loads but in some static pages the script manager is not present since none of features of Asp.net ajax is used.
but even though i register my client script like below i get Sys is undefined error, why is
that so.
if(Sys){
Sys.Application.add_init(registerMyLibrary);
}
i had also tried below, but what the use when the above code itself throws error
if(Sys !== 'undefined'){
//register my library
}
Is there some other way i can register my library without the error on my way??
This is because it (
Sys) hasn’t been assigned in the global object or any shadowing context, which may be (read: likely is) another bigger issue.In any case,
if (window.Sys) { ... }will work as expected.The problem is the lookup resolution for
Sysfails and JavaScript raises the nice error (this is why the latter form with the!==also fails). This is not a problem when trying to access a property of thewindowobject explicitly, as shown above.windowis conveniently the global object in JavaScript in a browser.The
window.Sys !== undefinedvariant can be used as well, but I dislike it. Another alternative istypeof Sys != "undefined", but I dislike this even more. (This works becausetypeofis a special operator and will not raise an exception if the lookup fails opting to return “undefined” — the string — instead.)Happy coding.