Posted By

Neven on 11/18/11


Tagged

c#


Versions (?)

Detect web page refresh


 / Published in: C#
 

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.

  1. private bool refreshState;
  2. private bool isRefresh;
  3.  
  4. protected override void LoadViewState(object savedState)
  5. {
  6. var AllStates = (object[]) savedState;
  7.  
  8. base.LoadViewState(AllStates[0]);
  9. refreshState = bool.Parse(AllStates[1].ToString());
  10. isRefresh = refreshState == (bool) Session["IsRefresh"];
  11. }
  12.  
  13. protected override object SaveViewState()
  14. {
  15. Session["IsRefresh"] = refreshState;
  16. var AllStates = new object[2];
  17.  
  18. AllStates[0] = base.SaveViewState();
  19. AllStates[1] = !refreshState;
  20. return AllStates;
  21. }
  22. public void DoWork()
  23. {
  24. if(!isRefresh)
  25. {
  26. // your work here
  27. }
  28. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: vtoman on November 18, 2011

Wow that's so cool. Good job!

You need to login to post a comment.