I have the following structure on a usercontrol that is loaded by a page (Parent UC):
<UpdatePanel>
<UpdatePanel>
.. In the codebehind, it loads a Child user control at runtime
</UpdatePanel>
</UpdatePanel>
The UC has OnPageLoad registers a script.
ScriptManager.RegisterStartupScript(this, typeof(Page), "Load_" + this.ClientID, base.GetRegisterScript(this.ClientID), true);
The JS function never gets executed on async postbacks. If i remove the UpdatePanels, it works as expected
EDIT: Used this.GetType() instead of typeof(Page) but no luck
EDIT Again:
Matt - I tried to replace the typeof(Page) with the UC name. Here's the updated line:
ScriptManager.RegisterStartupScript(this, typeof(TemplateAreaTypeOne), "Load_" + this.ClientID, "...JS function here,,", true);
To clarify, the Page loads the Parent UC that has these UpdatePanels. The ParentUC then loads the ChildUC and the ScriptManager.RegisterStartuScript is used in teh ChildUC
EDIT
The markup has:
<script type="text/javascript">
//<![CDATA[
; findControl('PageLoadedHiddenTxtBox').value ='Set';OnLoadBegin('ctl00_WorkSpaceContent_ctlUnion1_ctlUnion1Child','Edit');OnLoadEnd('ctl00_WorkSpaceContent_ctlUnion1_ctlUnion1Child','Edit');
document.getElementById('ctl00_WorkSpaceContent_informationSummary').dispose = function() {
Array.remove(Page_ValidationSummaries, document.getElementById('ctl00_WorkSpaceContent_informationSummary'));
}
//]]>
</script>
Note that the functions that are called are the OnLoadBegin and OnLoadEnd that have been added to the HTML
EDIT AGAIN
Got it to work using:
ScriptManager.RegisterStartupScript(this.Page, typeof(Page),....)
Not sure why it works when I use the reference to the Page.
- Will this work if I have multiple controls on the Page?
- Why does it work when I use a reference to the page?