What I have now is code for setting ViewState or Session of desired variable:
if (ViewState["currentPage"] != null)
{
currentPage = Convert.ToInt32(ViewState["currentPage"].ToString());
}
else
{
currentPage = 0;
ViewState["currentPage"] = currentPage.ToString();
}
currentPage field is global with default value of zero in CodeBehind (public int currentPage = 0;) and therefore its initial value is zero whenever the page is loaded. So I wrote these few lines to save its last value. Just to mention that wherever currentPage value is changed in CodeBehind, I added "ViewState["currentPage"] = currentPage.ToString();" in line after.
What I want is universal function that takes two arguments, variable and value, for setting ViewState according to code above. So if necessary, I can just call method, something like that: setViewState(currentPage, 0)