简体   繁体   English

与UpdatePanel结合使用时,Javascript不起作用

[英]Javascript is not working when used with UpdatePanel

I placed the following code in two pages. 我将以下代码放在两页中​​。

  1. A simple aspx page, there it worked well. 一个简单的aspx页面,效果很好。
  2. A page contains a lot of controls and Update Panels. 一个页面包含许多控件和更新面板。 There the code did not work. 那里的代码不起作用。 So I experimented with PageRequestManager. 所以我尝试了PageRequestManager。

Anybody know what should I do to execute the same in context of Case 2 . 任何人都知道在情况2的情况下我应该怎么做才能执行相同的操作。

StringBuilder jScript = new StringBuilder();

jScript.Append("<script type='text/javascript'>");
jScript.Append("Sys.WebForms.PageRequestManager.getInstance().add_endRequest(AlertMe);");
jScript.Append("function AlertMe() {");
jScript.Append("    alert('Hi Hoo')");
jScript.Append("}");
jScript.Append("AlertMe();");
jScript.Append("</script>");

Page.ClientScript.RegisterStartupScript(typeof(string), "save_as", jScript.ToString());

i am not sure i understand you right, but may be you are searching for function 我不确定我是否理解正确,但是可能您正在寻找功能

ScriptManager.RegisterStartupScript() ScriptManager.RegisterStartupScript()

because Page.ClientScript is obsolete now, and it's function "RegisterStartupScript" does not work with update panels async postbacks. 因为Page.ClientScript现在已过时,并且它的功能“ RegisterStartupScript”不适用于更新面板异步回发。

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

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