RegisterStartupScript不适用于ScriptManager,Updatepanel.这是为什么? [英] RegisterStartupScript doesn't work with ScriptManager,Updatepanel. Why is that?
本文介绍了RegisterStartupScript不适用于ScriptManager,Updatepanel.这是为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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
触发和更新面板.而且警报消息不会在timer_tick事件中显示
timer_click
trigggers and update panel. And the alert message doesnt show up on timer_tick event
推荐答案
使用UpdatePanel时,将无法像尝试使用ClientScript那样调用JavaScript.您必须改为使用ScriptManager.RegisterStartupScript
.
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.
因此更改您的
Page.ClientScript.RegisterStartupScript(this.GetType(), "myKey", javaScript);
到
ScriptManager.RegisterStartupScript(updatePanelId,updatePanelId.GetType(), "alert", javaScript, true);
这篇关于RegisterStartupScript不适用于ScriptManager,Updatepanel.这是为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文