我在页面加载的usercontrol上有以下结构(父UC):
<UpdatePanel>
<UpdatePanel>
.. In the codebehind, it loads a Child user control at runtime
</UpdatePanel>
</UpdatePanel>
UC让OnPageLoad注册一个脚本。
ScriptManager.RegisterStartupScript(this, typeof(Page), "Load_" + this.ClientID, base.GetRegisterScript(this.ClientID), true);
JS函数永远不会在异步回发上执行。如果我删除UpdatePanels,它按预期工作
编辑:使用this.GetType()而不是typeof(Page)但没有运气
再次编辑:
马特 - 我试图用UC名称替换typeof(Page)。这是更新的行:
ScriptManager.RegisterStartupScript(this, typeof(TemplateAreaTypeOne), "Load_" + this.ClientID, "...JS function here,,", true);
为了澄清,页面加载了具有这些UpdatePanel的父UC。然后ParentUC加载ChildUC和ScriptManager.RegisterStartuScript用于ChildUC
修改
标记有:
<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>
请注意,调用的函数是已添加到HTML的OnLoadBegin和OnLoadEnd
再次编辑
使用它来工作:
ScriptManager.RegisterStartupScript(this.Page, typeof(Page),....)
当我使用对页面的引用时,不确定它为什么会起作用。
答案 0 :(得分:2)
你的registertartupscript需要定位控件而不是页面不使用typeof(页面)