Javascript Alert Box does not Display
-
Good Evening Guys, Today its my Birthaday. :) I have a If statement that i use to return an integer that will mean Success or Failure , now am testing for that integer in my ASP.NET 2.0 Page lke this
if (Res == 1)
{Response.Write(@"<script> alert('You have Successfully Registred');</script>");
Response.Redirect("login.aspx", false); } else {
Response.Write(@"<script> alert('Invalid Data has been Entered');</script>");
Now if the value is 1, then it should Display the Message and after the Message has been Clicked it should move to the login Page. Now my Problem is that it moves to the Login Page without a Alert Message being Displayed And the send Alert for invalid Entry, will not show anythingm, there is a Warning sign on my Page at the Bootom left of my Page. What is wrong with my Javascript Thanks
Vuyiswa Maseko, Sorrow is Better than Laughter, it may Sadden your Face, but It sharpens your Understanding VB.NET/SQL7/2000/2005 http://vuyiswamb.007ihost.com http://Ecadre.007ihost.com vuyiswam@tshwane.gov.za
-
Good Evening Guys, Today its my Birthaday. :) I have a If statement that i use to return an integer that will mean Success or Failure , now am testing for that integer in my ASP.NET 2.0 Page lke this
if (Res == 1)
{Response.Write(@"<script> alert('You have Successfully Registred');</script>");
Response.Redirect("login.aspx", false); } else {
Response.Write(@"<script> alert('Invalid Data has been Entered');</script>");
Now if the value is 1, then it should Display the Message and after the Message has been Clicked it should move to the login Page. Now my Problem is that it moves to the Login Page without a Alert Message being Displayed And the send Alert for invalid Entry, will not show anythingm, there is a Warning sign on my Page at the Bootom left of my Page. What is wrong with my Javascript Thanks
Vuyiswa Maseko, Sorrow is Better than Laughter, it may Sadden your Face, but It sharpens your Understanding VB.NET/SQL7/2000/2005 http://vuyiswamb.007ihost.com http://Ecadre.007ihost.com vuyiswam@tshwane.gov.za
You can not send two responses to one request, so you can't both have a page containing the Javascript and a page for the redirect. When you do the redirect the current page (where you added the script) is scrapped, and a redirect page is sent instead. So the reason that the alert doesn't show up is that you removed it. You either have to make the login page show the alert, or do the redirect using Javascript. When you get a warning sign at the bottom of the page, there is an error message. Double click the warning sign to display the error message. It's probably because you put the script in the wrong place in the page. You should not use Response.Write at all, unless you take over the responsability for the page completely and write out the entire page with Response.Write. If you use Response.Write to put the script in the page, you will write it before the actual html document, which will keep it from working properly. Use the ClientScript.RegisterStartupScript method to add scripts to the page.
Despite everything, the person most likely to be fooling you next is yourself.
-
Good Evening Guys, Today its my Birthaday. :) I have a If statement that i use to return an integer that will mean Success or Failure , now am testing for that integer in my ASP.NET 2.0 Page lke this
if (Res == 1)
{Response.Write(@"<script> alert('You have Successfully Registred');</script>");
Response.Redirect("login.aspx", false); } else {
Response.Write(@"<script> alert('Invalid Data has been Entered');</script>");
Now if the value is 1, then it should Display the Message and after the Message has been Clicked it should move to the login Page. Now my Problem is that it moves to the Login Page without a Alert Message being Displayed And the send Alert for invalid Entry, will not show anythingm, there is a Warning sign on my Page at the Bootom left of my Page. What is wrong with my Javascript Thanks
Vuyiswa Maseko, Sorrow is Better than Laughter, it may Sadden your Face, but It sharpens your Understanding VB.NET/SQL7/2000/2005 http://vuyiswamb.007ihost.com http://Ecadre.007ihost.com vuyiswam@tshwane.gov.za
-
Good Evening Guys, Today its my Birthaday. :) I have a If statement that i use to return an integer that will mean Success or Failure , now am testing for that integer in my ASP.NET 2.0 Page lke this
if (Res == 1)
{Response.Write(@"<script> alert('You have Successfully Registred');</script>");
Response.Redirect("login.aspx", false); } else {
Response.Write(@"<script> alert('Invalid Data has been Entered');</script>");
Now if the value is 1, then it should Display the Message and after the Message has been Clicked it should move to the login Page. Now my Problem is that it moves to the Login Page without a Alert Message being Displayed And the send Alert for invalid Entry, will not show anythingm, there is a Warning sign on my Page at the Bootom left of my Page. What is wrong with my Javascript Thanks
Vuyiswa Maseko, Sorrow is Better than Laughter, it may Sadden your Face, but It sharpens your Understanding VB.NET/SQL7/2000/2005 http://vuyiswamb.007ihost.com http://Ecadre.007ihost.com vuyiswam@tshwane.gov.za
You can do in follwoing way if (Res == 1) { this.ClientScript.RegisterStartupScript(this.GetType(), "key", "myfunction();", true); ) and in myfunction function just show the alert message and redirect user to Login Page <script type="text/javascript"> function myfunction() { alert('You have Successfully Registred') window.location.href='Login.aspx'; } </script>
Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... " Check My Blog
-
You can do in follwoing way if (Res == 1) { this.ClientScript.RegisterStartupScript(this.GetType(), "key", "myfunction();", true); ) and in myfunction function just show the alert message and redirect user to Login Page <script type="text/javascript"> function myfunction() { alert('You have Successfully Registred') window.location.href='Login.aspx'; } </script>
Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... " Check My Blog
hi Thank you , its working
Vuyiswa Maseko, Sorrow is Better than Laughter, it may Sadden your Face, but It sharpens your Understanding VB.NET/SQL7/2000/2005 http://vuyiswamb.007ihost.com http://Ecadre.007ihost.com vuyiswam@tshwane.gov.za
-
Page.RegisterStartupScript("hai", "alert('hai')") the above display alert box
your's subbu
Thanks it works
Vuyiswa Maseko, Sorrow is Better than Laughter, it may Sadden your Face, but It sharpens your Understanding VB.NET/SQL7/2000/2005 http://vuyiswamb.007ihost.com http://Ecadre.007ihost.com vuyiswam@tshwane.gov.za