Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i used javascript to make a pop an alert message and refresh the page . but what happens is when is click the button the alert shows then it is not stopping from reloading. here's my code.

What I have tried:

ClientScript.RegisterStartupScript(Me.GetType, "alert", "alert('This student record already exist');window.location.reload();", True)
Posted
Updated 18-Jan-17 11:42am
Comments
F-ES Sitecore 17-Jan-17 9:04am    
The js isn't being executed right away, all RegisterStartupScript does is add js to the html that is sent to the browser so that js is executed when the page has finished processing. So that line is not executing js right away and it is not stopping the rest of your .net code from running. Your .net code runs first on the server then hands the results to the client (including code injected via RegisterStartupScript) to execute.

1 solution

I think you need a confirmation message not the alert here is how

JavaScript
var r = confirm("Successful Message!");
    if (r == true){
      window.location.reload();
    }

or here is an alternate.
JavaScript
if(alert('Alert For your User!')){}
else    window.location.reload(); 

short version
JavaScript
if(!alert('Alert For your User!')){window.location.reload();}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900