How to Register Scripts Loaded in Callbacks

  • 2 minutes to read

If a script appears on a callback, browsers do not recognize it. DevExpress extensions implement a client-side mechanism that evaluates and executes scripts passed to a client in callbacks.

There are two types of scripts: external scripts and inline scripts.

Register an External Script

An external script is loaded from an external file. This script is registered only once for the first callback. Add the dxis_ prefix to the id attribute value to register an external script.

<script id="dxis_myCode1" src="MyJavaScript.js" type="text/javascript"></script>  

View Example: How to register and execute a JavaScript downloaded to the client via a callback (standalone JS file)

Register an Inline Script

An inline script is embedded in HTML. This code is registered and executed on every callback. Add the dxss_ prefix to the id attribute value to register an inline script.

<script id="dxss_myCode2" type="text/javascript">  
  alert("This is custom script block");  
</script> 

View Example: How to register and execute a JavaScript downloaded to the client via a callback

Access a Script Specified in Another Callback Container

If you load a script in the CallbackPanel container’s callback and then use the script outside the container, you should explicitly assign functions in your script to the global window object.

<script id="dxss_myCode3" type="text/javascript">  
  window.showText = function () {  
    alert('showText');  
  }  
</script>

<input type="button" value="Show text" onclick="window.showText();"/>