Click here to Skip to main content
15,312,536 members
Articles / Programming Languages / Javascript
Alternative
Tip/Trick
Posted 22 Nov 2011

Stats

8.7K views

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

Rate me:
Please Sign up or sign in to vote.
4.00/5 (2 votes)
22 Nov 2011CPOL
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"); ...
C#
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

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Nicolò Beltrame
Software Developer
Italy Italy
No Biography provided

Comments and Discussions

 
GeneralReason for my vote of 3 nothing new Pin
itaitai26-Nov-11 22:02
professionalitaitai26-Nov-11 22:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.