I need to find whether the user clicking the browser back button or Refresh button.
I need to redirect the page to Error page when he clicks the back or refresh button.
Implement a PageToken using a guid/or timestamp stored in session and compare the value to a hidden field on the form. I did this via a PageToken Class. If the value from the hidden field and the session variable don't match then you're out of synch and you handle that. The trick is to map all events on your page.
public void GeneratePageToken()
{
SessionVariables currSession = new SessionVariables();
hfMasterPageToken.Value = System.DateTime.Now.ToString();
currSession.PageToken = hfMasterPageToken.Value;
}
public string GetLastPageToken
{
get
{
SessionVariables currSession = new SessionVariables();
return currSession.PageToken;
}
}
public bool TokensMatch
{
get
{
SessionVariables currSession = new SessionVariables();
return (currSession.PageToken != null
&& currSession.PageToken == hfMasterPageToken.Value);
}
}
In your Event method before your regular code:
if (this.TokensMatch == false)
{
//Reload the data.
//Generates a NewPageToken (this.GeneratePageToken();)
ReloadDataMethod();
this.MessageToUser =
"Data reloaded. Click Edit or Insert button to change.";
this.MessageType = MessageToUserType.Success;
this.DisplayMessageToUser = true;
return;
}