User controls : Loading external javascript resources

Official Content

There are different ways to reference an external javascript resource for a User Control.

Basically, an external javascript resource is added in the User Control definition file, using the ReferencedFiles tag. This adds the script reference in the head element of the page.

But in some cases if the User Control uses external resources, it may be necessary to add those external resources dynamically.

To do so, you can use some methods available in the gxgral.js.


Look at the example of the StockChart Control.

Depending on the "skin" property of the Chart, a different javascript has to be loaded to display the chart using that skin.

In the JScript Runtime Render of the user control, in the show method, the following method is invoked.

this.setGXSkinAndExecute = function ()
        var buffer = gx.util.resourceUrl(gx.basePath + gx.staticDirectory + "StockChart/js/themes/" + this.Skin + ".js", false);
        var fun = function ()
        // Load Skin first and then execute        
        gx.http.loadScript(buffer, fun.closure(this));

Note that the path of the javascript library which is part of the dependencies, is assigned to a "buffer" variable and then loaded dynamically using the gx.http.loadScript function of the gxgral.js.

See Also

Useful Javascript functions available in the gxgral.js