Reputation: 31
I have a login.aspx page. There is a validation in another page say FirstPage.aspx once login successful, and if the validation fails,page will be redirected back to "login.aspx?status=false". Then the error message is assigned a label in Login.aspx page and it will be displayed. Now, the requirement is, if I click on browser's refresh button now, teh URL should get changed to "login.aspx".
How to achieve this. Any help is greatly appreciated.
Thanks in advance
Upvotes: 3
Views: 988
Reputation: 86749
You can kind of do this (detect a page refresh) in a couple of way - see Detecting Page Refreshes :: Using JavaScript on Client-Side.
The simplest approach seems to be to use hidden form variables. Apparently form variables are maintained across page refreshes by most modern browsers, by updating the value of a hidden field with JavaScript we can take advantage of this to detect when the page is refreshed:
<input type="hidden" name="visited" value="" />
if( document.refreshForm.visited.value == "") {
// This is a fresh page load
document.refreshForm.visited.value = "1";
} else {
// This is a page refresh
// either redirect to login.aspx, or just update the page accordingly
}
You can either redirect the user when you detect a page refresh, or better would be to alter the appearance of the page accordingly (which prevents an extra refresh of the page)
Upvotes: 1