Asp.net RegisterStartupScript和多个控件
我有一个加载childUserControl的parentUserControl。将parentUserControl的多个实例(例如3)添加到主机页 在parentUserControl的PageLoad上,我注册了JS:Asp.net RegisterStartupScript和多个控件,asp.net,Asp.net,我有一个加载childUserControl的parentUserControl。将parentUserControl的多个实例(例如3)添加到主机页 在parentUserControl的PageLoad上,我注册了JS: ScriptManager.RegisterStartupScript(this, typeof(Page), keyJSLoadBegin, "OnParentLoad();", true); ScriptManager.RegisterStartupScript(th
ScriptManager.RegisterStartupScript(this, typeof(Page), keyJSLoadBegin, "OnParentLoad();", true);
ScriptManager.RegisterStartupScript(this, typeof(Page), keyJSLoadBegin, "OnChildLoad();", true);
在hte childUserControl的PageLoad上,我注册了JS:
ScriptManager.RegisterStartupScript(this, typeof(Page), keyJSLoadBegin, "OnParentLoad();", true);
ScriptManager.RegisterStartupScript(this, typeof(Page), keyJSLoadBegin, "OnChildLoad();", true);
当我导航到该页面时,会出现JS错误。导致此错误的行是(在视图源中):
很明显,这些电话是不正常的
有人知道为什么吗
编辑:
问题似乎与此处的错误有关:
建议立即注册所有相关脚本。在我的情况下,这是不可能的,因为脚本位于不同的用户控件中
是否有人找到了解决此问题的方法?ASP.NET中的控件模型旨在对代码进行完全封装。每个控件应独立于其他控件运行,且不依赖于负载顺序(理想情况下甚至不依赖于存在)。你应该重新考虑你的方法。我不明白为什么会发生这种情况,但我的意见是: 我认为您应该通过一种方法公开子控件的脚本。在父控件中,按所需顺序连接它们,然后在一个位置注册页面