How to get alert message before redirect a page

If you want to put in .CS file, just try this:

var page = HttpContext.Current.CurrentHandler as Page;
           ScriptManager.RegisterStartupScript(page, page.GetType(), "alert", "alert('" + msg +"');window.location ='"+ aspx +"';", true);

Your code is opening window but your asking for a redirect, below is an example of a redirect:

ScriptManager.RegisterStartupScript(this, this.GetType(), 
"alert", 
"alert('User details saved sucessfully');window.location ='frmDisplayUsers.aspx';", 
true);

You need to write:

 ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", " alert('User details saved sucessfully'); window.open('frmDisplayUsers.aspx');", true);

Please note that I have removed the script tags as the last parameter true means you must not use the script tag.

This code worked for me. If you have any problem let me know. In addition you can use setTimeout to delay the window open that might not be a very bad choice.