Quantcast
Channel: ASP.NET AJAX + Ajax Control Toolkit (ACT)
Viewing all articles
Browse latest Browse all 5678

Sys.Application._loaded do not recognize dynamic usercontrols

$
0
0

Hi experts,

Our team uses a function that basically waits for controls much like the $.ready().

function waitForControls(callback) {
/// <summary>
/// Waits for the directly in the page/control declared usercontrols and then calls the callback-method.
/// If the controls already have been instantiated, callback() gets executed immediately.
/// </summary>
/// <param name="callback">The callback-function, which should get executed after the controls are initialized</param>

if (exists(window.Sys)) {
// simple control-instantiation handler
// works perfectly fine for simple control-init-checks
if (!Sys.Application._loaded) {
// create handler-Reference (non-anonymous function)
var loadHandler = function () {
callback();
// we just want to execute this function ONCE
Sys.Application.remove_load(loadHandler);
};

// effectively add the handler to the system
Sys.Application.add_load(loadHandler);
} else {
// controls are already available
// -> instantly call the callback-method

return callback();
}
}

return null;
}

This works fine for static controls in the markup and wait for the script controls to be initialized.

My problem is for dynamic usercontrols that registers inidividual scriptcontrols. 

Ex: i have a usercontrol1 which dynamically loads usercontrol2

usercontrol2 has bunch of child usercontrols in itself staticly in markup.

My problem occurs when my usercontrol2 initializes its script control. it calls child usercontrol scriptcontrol js functions (something like editor[0].control.set_content(xml)) . but this time the scriptcontrol of the child is not yet initialized so i have to waitforcontrols(). but it seems that Sys.Application._loaded do not realize child usercontrols from the dynamic usercontrol2.

my codes calls the non existing function and throws a js error. I debug and continue the step and only right after it initializes the script control of the child usercontrol.

I tried the $.ready() instead of the waitforcontrols but same issue.

Anybody can point me to the right solution or workaround? 

Thanks a lot.

-mailman


Viewing all articles
Browse latest Browse all 5678

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>