fable fable - 1 month ago 16
ASP.NET (C#) Question

Response.Write after Response.Redirect(Request.RawUrl)

I want to when push save button write a javascript message and Response.Redirect same page as empty form (RawUrl) on asp.net

Response.Write("<script LANGUAGE='JavaScript' >alert('Record successful.')</script>");
Response.Redirect(Request.RawUrl);


But I cant see any message just redirecting page. How can I show a message and then redirect same page?

Answer

You should do redirect via Javascript after alert has been shown.

Response.Write(@"
     <script>
        alert('Record successful.');
        window.location = '" + Request.RawUrl + @"';
    </script>
");

You can also set timeout

Response.Write(@"
     <script>
        alert('Record successful.');
        setTimeout(function(){            
            window.location = '" + Request.RawUrl + @"';
        }, 2000);
    </script>
");

And Javascript will redirect user 2s after clicking message box.