How to display message before redirect?

How to get alert message before redirect a page

  • I'm using vs 2010. I need to display the message to user and redirect the page. I use the below line. ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", "<script> alert('User details saved sucessfully');window.open('frmDisplayUsers.aspx');</script>", true); But I didn't get the alert message and the page was directly redirected. How to get alert message?

  • Answer:

    Your code is opening window but you 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);

Pooja at Stack Overflow Visit the source

Was this solution helpful to you?

Other answers

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.

Kamal Deep Singh

The best way, if possible, is to put the code into the OnClientClick. <asp:Button OnClientClick=" alert('blah?');" runat="server" /> The problem with putting it into a startupscript is that the startupscript is run on postback, not real time. The redirect will happen before the postback. (possibly) The other solution of course is to put the redirect into the startupscript code. The page will post back, the script will run and then it will redirect.

thantos

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.