What I want to do is when user clicks a submit button, the backend code will add it into database, and show a success message in client before the page is redirect to the next page. How do I write code in backend? I use
this.ClientScript.RegisterClientScriptBlock(this.GetType(), "clientScipt", "<script>alert('Done!');</script>");
But the message never shows, it just jumps into next page directly.
Help is appreciated.
In the few apps where this has been requested, we have a “Success.aspx” page. The page simply shows a success message, and then does a timed redirect to the next page. Usually, we pass along the redirect target as a POST variable.
The timed redirect is handled by Javascript similar to this:
We do it via javascript (client-side) because you can do a redirect in server-side code, but not with a delay. The Redirect is immediate and the “Success” message is never displayed.
I do feel compelled to add, however, that these “Success” pages are somethign we stopped doing unless the user explicitly asks for it because they become very annoying after a while. They seem like a good idea at the time, but provide a very poor suer experience. You might be better served just putting a “Success” message next to the buton and using the same setTimeout function to then set the display of that “Success” to “none” so that it disappears after a few seconds.