Wednesday, 6 June 2012

ClientScript.RegisterStartupScript+ navigating to another page + while pressing back button alert


 ClientScript.RegisterStartupScript(this.GetType(), "script", "alert('hello !');__doPostBack('__Page', 'EmptyPostback');", true);


To avoid alert message using RegisterStartupScript  while click on browser back button.


When we register the startup script with the alert, immediately follow the alert statement with one which will refresh the page. This ensures that the startup script is removed from the page as soon as the OK is clicked, and if the user returns to the page the alert pop up does not reappear.

No comments:

Post a Comment