I'm using C# to create a website and I'm trying to show a message box. I'm trying to use JavaScript for this situation and it runs if I do the following:
Response.Write("<script LANGUAGE='JavaScript' >alert('Login Successful')</script>");
However if instead I do this:
Response.Write("<script LANGUAGE='JavaScript' >alert('Login Successful')</script>");
Response.Redirect("~/admin.aspx");
The message box doesn't get shown.
Why is this and how can I fix it?
By doing a Response.Redirect right after you're actually sending a 302 redirect to the client, so the alert is never actually being rendered in the user's browser. Instead, try something like this
Response.Write("<script LANGUAGE='JavaScript' >alert('Login Successful');document.location='" + ResolveClientUrl("~/admin.aspx") +"';</script>");
Your Response.Redirect
call will fire and redirect the browser before the alert
has been shown to the user.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With