65.9K
CodeProject is changing. Read more.
Home

How to show the message and redirect to other page in ASP.NET

starIconstarIconstarIconstarIconemptyStarIcon

4.00/5 (2 votes)

Nov 22, 2011

CPOL
viewsIcon

9690

public static void MsgAlert(string message, string optURL) { Page page = (Page)HttpContext.Current.Handler; message = message.Replace("'", "\\'"); message = message.Replace("\r", "\\r"); message = message.Replace("\n", "\\n"); ...

public static void MsgAlert(string message, string optURL)
        {
            Page page = (Page)HttpContext.Current.Handler;
            message = message.Replace("'", "\\'");
            message = message.Replace("\r", "\\r");
            message = message.Replace("\n", "\\n");
            string script = "alert('" + message + "');";
            if(!string.IsNullOrEmpty(optURL)) {
                script += "window.location = '" + optURL + "';";
            }
            ScriptManager.RegisterStartupScript(page, typeof(Page), "Alert", script, true);
        }
Quote:
I use this method in a library. Note the use of the optional parameter optUrl