Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to show message box in asp.net

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?

like image 856
Simon Huynh Avatar asked Dec 13 '22 08:12

Simon Huynh


2 Answers

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>");
like image 57
redec Avatar answered Dec 14 '22 20:12

redec


Your Response.Redirect call will fire and redirect the browser before the alert has been shown to the user.

like image 26
ipr101 Avatar answered Dec 14 '22 21:12

ipr101