置于UpdatePanel中时,无法使用ClientScript.RegisterStartupScript显示Alert

时间:2013-08-26 02:13:36

标签: c# javascript asp.net .net updatepanel

实际上,我需要显示Success Message,然后点击OK后,Redirect我应该转到另一个Page
截至目前,一切正常。但在放置UpdatePanel后,Alert未显示。

我的代码:

ClientScript.RegisterStartupScript(typeof(Page), "Create Time Table", "<script language='JavaScript'>alert('Time Table Created Successfully.'); window.location.href = 'create.aspx';</script>");

我尝试过:

ClientScript.RegisterStartupScript(typeof(Page), "Create Time Table", "<script language='JavaScript'>alert('Time Table Created Successfully.'); window.location.href = 'create.aspx';</script>",true);

ClientScript.RegisterStartupScript(typeof(Page), "Create Time Table", "<script language='JavaScript'>alert('Time Table Created Successfully.'); window.location.href = 'create.aspx';</script>",false);

但是,这些都没有奏效:(

1 个答案:

答案 0 :(得分:4)

如果您有更新面板,则提供更新面板ID及其类型如下

ScriptManager.RegisterStartupScript(
                UpdatePanelID,
                UpdatePanelID.GetType(), 
                "Create Time Table", 
                " alert('Time Table Created Successfully.'); window.location.href = 'create.aspx';",
                true);