Return to Snippet

Revision: 53284
at November 18, 2011 01:19 by Neven

Initial Code
private bool refreshState;
private bool isRefresh;

        protected override void LoadViewState(object savedState)
            var AllStates = (object[]) savedState;

            refreshState = bool.Parse(AllStates[1].ToString());
            isRefresh = refreshState == (bool) Session["IsRefresh"];

        protected override object SaveViewState()
            Session["IsRefresh"] = refreshState;
            var AllStates = new object[2];

            AllStates[0] = base.SaveViewState();
            AllStates[1] = !refreshState;
            return AllStates;
public void DoWork()
     // your work here

Initial URL

Initial Description
Overwrite LoadViewSate and SaveViewState page methods.
SaveViewState is called on initial page load and that is the place to save your negated flag to Session. 
This value should be compared in LoadViewState and if the values are the same it means that the page is refreshed.

Initial Title
Detect web page refresh

Initial Tags

Initial Language