protected void timer1_Tick(object sender, EventArgs e) { foreach (RepeaterItem item in rpChat.Items) { TextBox txt = item.FindControl("txtChatMessage") as TextBox; if (txt != null) { message[i] = txt.Text; i--; } } lblStatusChat.Text = ""; RepeaterBind(); string javaScript = "<script language=JavaScript>\n" + "alert('Button1_Click client-side');\n" + "</script>"; Page.ClientScript.RegisterStartupScript(this.GetType(), "myKey", javaScript); }
timer_click
trigggers and update panel. And the alert message doesnt show up on timer_tick event
The script block that is rendered by the RegisterStartupScript method executes when the page finishes loading but before the page's client onload event is raised. Startup script blocks are located at the bottom of the rendered ASP.NET page just before the </form> tag.
I have used ScriptManager. RegisterStartupScript() method in order to show an alert when particular thing happens in back end.It works fine in page load method but not in particular method which is called when a specific button is clicked .
When you use an UpdatePanel, then you can not call JavaScript using ClientScript as you have tried to. You have to use ScriptManager.RegisterStartupScript
instead.
So change your
Page.ClientScript.RegisterStartupScript(this.GetType(), "myKey", javaScript);
to
ScriptManager.RegisterStartupScript(updatePanelId,updatePanelId.GetType(), "alert", javaScript, true);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With