Hello,
I was searching for a way of detecting in my C# code if the page had been refreshed (f5).
First I don’t know if a jQuery/JavaScript solution would be better than a fully C# ASP.Net. So... the first question would be: What would make you choose one over the other?
And the third, and most important part, is if someone would help me with this. Some good tutorial, or article… anything. I tried some solutions out there… but maybe, because of my lack of knowledge they didn’t work.
Thanks in advance.
update 1
I tried to do Hightechrider solution, because it seems pretty simple to implement. So I typed this code:
public bool IsRefresh { get; set; }
protected override void OnPreInit(EventArgs e)
{
base.OnPreInit(e);
IsRefresh = false;
if (Page.Request.AppRelativeCurrentExecutionFilePath == Profiles.User.LastPageUrl &&
!Page.IsPostBack)
IsRefresh = true;
}
PS: The Profiles.User.LastPageUrl is a session variable that I have created for other purposes, but suites the needs of this one to. So that is not some built in property.
However, after a couple of tests I got to the conclusion that a page could be a PostBack and Refresh at the same time. Because a user could press a button and after that, hit refresh. So this scenario invalidates my previous code, because of the !Page.IsPostBack. I am still seeking for a simple straight solution to this.