/ 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.
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.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
private bool refreshState; private bool isRefresh; protected override void LoadViewState(object savedState) { var AllStates = (object[]) savedState; base.LoadViewState(AllStates[0]); refreshState = bool.Parse(AllStates[1].ToString()); isRefresh = refreshState == (bool) Session["IsRefresh"]; } protected override object SaveViewState() { Session["IsRefresh"] = refreshState; AllStates[0] = base.SaveViewState(); AllStates[1] = !refreshState; return AllStates; } public void DoWork() { if(!isRefresh) { // your work here } }