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

759 Views Asked by At

I have an alert message and followed by a Response.Redirect block in Page_Init

The Response.Redirect works and redirects to a spectic page. But the alert msg is not showing.

I need the user to click the OK button in the alert msg after that only the page should rediret..

Please help.

Sample code:

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

2

There are 2 best solutions below

0
Amit Joki On

It will never work because the context is lost. The alert() should be done in index.aspx.cs.

Here is the possible implementation:

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

And in index.aspx.cs Page_Load:

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

Why not do it in pure JavaScript?

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