Disposing dynamically created behaviors(extenders) within an update panel
-
Guys; As you might know, all extenders are created by calling the function
$create()
just on the eventSys.Application.init
. And disposed by calling the function$find('_componentId_').dispose()
ether on the eventSys.Application.unload
(closing the page) or by updating the containingUpdatePanel
. My question is; in case we create the behavior(the extender) dynamically by calling the function$create()
through the client script, then how to register disposing it when theUpdatePanel
is updated?Help people,so poeple can help you.
-
Guys; As you might know, all extenders are created by calling the function
$create()
just on the eventSys.Application.init
. And disposed by calling the function$find('_componentId_').dispose()
ether on the eventSys.Application.unload
(closing the page) or by updating the containingUpdatePanel
. My question is; in case we create the behavior(the extender) dynamically by calling the function$create()
through the client script, then how to register disposing it when theUpdatePanel
is updated?Help people,so poeple can help you.
We can achieve that by by calling the function
Sys.WebForms.PageRequestManager._registerDisposeScript();
which registers the the component on updating the parentUpdatePanel
just like the code below:Sys.WebForms.PageRequestManager.getInstance()._registerDisposeScript('parentupdatepanelid', 'var component = $find("componentid"); if (component != null)component.dispose()';
The disposing script(the second argument) is executed by the function
Sys.WebForms.PageRequestManager._updatePanel
which is called when an UpdatePanel is updated. (the code below)function Sys$WebForms$PageRequestManager$_updatePanel(updatePanelElement, rendering) {
for (var updatePanelID in this._scriptDisposes) {
if (this._elementContains(updatePanelElement, document.getElementById(updatePanelID))) {
var disposeScripts = this._scriptDisposes[updatePanelID];
for (var i = 0, l = disposeScripts.length; i < l; i++) {
eval(disposeScripts[i]);
}
delete this._scriptDisposes[updatePanelID];
}
}
this._destroyTree(updatePanelElement);
updatePanelElement.innerHTML = rendering;
}I added the if statement to the disposing script because the component can be disposed before the
UpdatePanel
is updated so the function$find()
would return anull
and we would have a Null Reference Exception. So what about the behaviors that is created afterExtenderControls
on thePage
that have disposing scripts of'$find("_componentid_").dispose();'
?Help people,so poeple can help you.