.NET to JavaScript
Calling JavaScript from .NET is pretty simple. There are two ways of doing this:
- Global JavaScript
- JavaScript isolation
We will go through both ways to see what the difference is.
Global JavaScript (the old way)
To access the JavaScript method, we need to make it accessible. One way is to define it globally through the JavaScript window object. This is a bad practice since it is accessible by all scripts and could replace the functionality in other scripts (if we accidentally use the same names).
What we can do, for example, is use scopes, create an object in global space, and put our variables and methods on that object so that we lower the risk a bit, at least.
Using a scope could look something like this:
<script>
window.myscope = {};
window.myscope.methodName = () => { alert("this has been called"); }
</script>
We create an object with the name myscope
. Then, we declare a method on that...