Javascript is not working when used with UpdatePanel

1.5k Views Asked by At

I placed the following code in two pages.

  1. A simple aspx page, there it worked well.
  2. A page contains a lot of controls and Update Panels. There the code did not work. So I experimented with PageRequestManager.

Anybody know what should I do to execute the same in context of Case 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());
1

There are 1 best solutions below

0
On BEST ANSWER

i am not sure i understand you right, but may be you are searching for function

ScriptManager.RegisterStartupScript()

because Page.ClientScript is obsolete now, and it's function "RegisterStartupScript" does not work with update panels async postbacks.