繁体   English   中英

Javascript function 没有被调用 - ASP.NET 和 UpdatePanel

[英]Javascript function doesn't get called - ASP.NET and UpdatePanel

我在由页面(父 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 function 永远不会在异步回发上执行。 如果我删除 UpdatePanel,它会按预期工作

编辑:使用 this.GetType() 而不是 typeof(Page) 但没有运气

再次编辑:

Matt - 我试图用 UC 名称替换 typeof(Page)。 这是更新的行:

ScriptManager.RegisterStartupScript(this, typeof(TemplateAreaTypeOne), "Load_" + this.ClientID, "...JS function here,,", true);

为了澄清,页面加载了具有这些更新面板的父 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),....)

不知道为什么当我使用对页面的引用时它会起作用。

  1. 如果我在页面上有多个控件,这会起作用吗?
  2. 为什么当我使用对页面的引用时它会起作用?

您的 registerstartupscript 需要针对控件而不是页面不使用 typeof(Page)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM