alert后面跟着一个Response.RRedirect();t发出警报消息

alert followed by a Response.Redirect() doesn't shoot the alert msg

本文关键字:消息 RRedirect 一个 alert Response      更新时间:2023-09-26

我有一条警报消息,后面是Page_Init 中的Response.RRedirect块

Response.RRedirect可以工作并重定向到幽灵页面。但是警报消息没有显示。

我需要用户点击警报消息中的"确定"按钮,然后只有页面应该重新显示。。

请帮忙。

样本代码:

ScriptManager.RegisterCleaintScriptBlock(this,this.GetType(),"alert('Success')",true);Response.RRedirect("index.aspx",false);

它永远不会工作,因为上下文丢失了。alert()应在index.aspx.cs中完成。

以下是可能的实现:

Response.Redirect("index.aspx?query=alert",false);

在index.aspx.cs Page_Load:中

if(Request["query"]=="alert")
{
    ScriptManager.RegisterClientScriptBlock(this.GetType(),"key","alert('Success')",true); 
}

为什么不使用纯JavaScript呢?

<script>
    (function() {
        alert("Success");
        window.location = "/index.aspx";
    })();
</script>