skip to Main Content

I have a web form which contains a submit button which updates the database.

After clicking the button I need to display a message and go back to the previous page after 2 seconds.

2

Answers


  1. Chosen as BEST ANSWER
    Response.AppendHeader("Refresh", "2;url=page.aspx");
    

    this works.


  2. Regardless on technologies you use, you can simply store "back link" in the URL as one of the GET parameters and then use this URL to redirect user back to the required page. For example, your link might look like this:

    /action/send/?backlink=/path/to/previous/page/
    

    Of course, this link should be URL encoded and will look like this:

    /action/send/?backlink=%2Fpath%2Fto%2Fprevious%2Fpage%2F
    

    You can also send this link using POST method, alongside with the query for the database you might send. After the link being passed to the backend, you can place this link as a destination for redirect on the page with the message you want to show. You can use redirect by <meta> tag in HTML document like this:

    <meta http-equiv="refresh" content="5;url=/path/to/previous/page/" />
    
    • 5 — Delay, amount of seconds before refresh will be fired;
    • url=/path/to/previous/page/ — Path for redirection.

    As another solution, you can write JavaScript code which will do the same thing. Minimal implementation will look like this:

    <script>
      // Wait for page to load
      window.addEventListener('load', function() {
        // Set the timer for redirection
        setTimeout(
          function () {
            location.href = '/path/to/previous/page/';
          },
          // Amount of milliseconds before refresh triggered
          5000
        );
      });
    </script>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search