i have a situation in what the user will keep a page/form open for couple of hours/days. After that time when the user comes to the page, even if i check cookies, i get other login variables, but the state of the controls is lost. Now when user clicks refresh,
instead of postback, a fresh request is made.
I have read a lot and found that the viewstate is itself stored in the session. so when the session expires the viewstate is gone.
How do i retain the viewstate, so that the selections remain the same the page refreshes.
Now i cannot store the current values of the selected fields in cookies as i have to apply this logic to a hell lot of pages.
Lets first talk about only Single page.
The code below is useless, but is something that i was using.
if (ViewState["AdminFlag"] != null)
Session["AdminFlag"] = ViewState["AdminFlag"].ToString();
if (Session["AdminFlag"] != null)
Admin_Flag = Session["AdminFlag"].ToString();
Master.ChkLogin();//checks cookies and populates to session
if (!IsPostBack)
{......}
In that case, you need to save your session in database instead of in memory. your session will never get expired. you need to serialize the object saving in session or viewstate.
I have read a lot and found that the viewstate is itself stored in the session.
By default, Viewstate is stored in a hidden field that is part of the page and sent to the client. There are ways to force it to be stored in Session but that's not the default.
There is something happening that you're not telling us, such as the user being directed to a login page when they submit the form after a period of time then coming back to the form, or something like that. I can't see how what you're describing is possible.
viewstatePostbackSession
I'm afraid I no longer use this forum due to the new point allocation system.
no, nothing is happening, as i have shared little code earlier,
I will elaborate it once again,
if (ViewState["AdminFlag"] != null)
Session["AdminFlag"] = ViewState["AdminFlag"].ToString();
if (Session["AdminFlag"] != null)
Admin_Flag = Session["AdminFlag"].ToString();
1] i want the AdminFlag to be retained, the viewstate to be retained.
2] if the user keeps the page open on his/her browser, again opens the tab and clicks the refresh data button, only the data in the grid should get refreshed as the user has already selected other details from the dropdowns.(I have few selection fields
like dropdown and date and a refresh button that refreshes the data)
3] Once done with this logic, i have to apply this logic all over my web application!.
Member
179 Points
149 Posts
Viewstate should never get expired
Jan 02, 2015 12:44 AM|sumeetssm|LINK
Hi,
i have a situation in what the user will keep a page/form open for couple of hours/days. After that time when the user comes to the page, even if i check cookies, i get other login variables, but the state of the controls is lost. Now when user clicks refresh, instead of postback, a fresh request is made.
I have read a lot and found that the viewstate is itself stored in the session. so when the session expires the viewstate is gone.
How do i retain the viewstate, so that the selections remain the same the page refreshes.
Now i cannot store the current values of the selected fields in cookies as i have to apply this logic to a hell lot of pages.
Lets first talk about only Single page.
The code below is useless, but is something that i was using.
viewstate Postback Session
Please mark as answer if helpful
Participant
1570 Points
495 Posts
Re: Viewstate should never get expired
Jan 02, 2015 01:23 AM|sumitjain231|LINK
In that case, you need to save your session in database instead of in memory. your session will never get expired. you need to serialize the object saving in session or viewstate.
for detail information please look at the following link. http://www.itorian.com/2012/09/aspnet-session-states-in-sql-server.html
http://msdn.microsoft.com/en-us/library/ms972429.aspx
viewstate Postback Session
Remember to click Mark as Answer on the post that helps to others.
Member
179 Points
149 Posts
Re: Viewstate should never get expired
Jan 02, 2015 04:04 AM|sumeetssm|LINK
Hi sumit, Thanks for replying.
Is there any other way too?
because storing into the database would add some more overheads.
(How can we do a viewstate Never expire?) How many diffrent ways are there.?
viewstate Postback Session
Please mark as answer if helpful
All-Star
160083 Points
13198 Posts
ASPInsiders
Moderator
Re: Viewstate should never get expired
Jan 02, 2015 12:15 PM|mbanavige|LINK
By default, Viewstate is stored in a hidden field that is part of the page and sent to the client. There are ways to force it to be stored in Session but that's not the default.
viewstate Postback Session
Member
179 Points
149 Posts
Re: Viewstate should never get expired
Jan 12, 2015 05:19 AM|sumeetssm|LINK
ohh!,
so i am wrong. thanks to point out. could you please enlighten a little more on that.
As it would be stored in hidden field, and will be part of the page, what will happen of it when the page is inactive for a certain amount of time.
What should happen of the same if the user comes back the next day with the same page open and just clicks on certain button on the same page.
What is happening in my case is that the page is firing a fresh refresh request instead of a postback!
viewstate Postback Session
Please mark as answer if helpful
Star
13653 Points
5480 Posts
Re: Viewstate should never get expired
Jan 12, 2015 05:57 AM|Ashim Chatterjee|LINK
How did you come to know that its a fresh request not the postback ?
viewstate Postback Session
Member
179 Points
149 Posts
Re: Viewstate should never get expired
Jan 12, 2015 09:41 AM|sumeetssm|LINK
i check
if(!ispostback)
i check the statements with the help of breakpoints
viewstate Postback Session
Please mark as answer if helpful
All-Star
37441 Points
9076 Posts
Re: Viewstate should never get expired
Jan 12, 2015 09:50 AM|AidyF|LINK
There is something happening that you're not telling us, such as the user being directed to a login page when they submit the form after a period of time then coming back to the form, or something like that. I can't see how what you're describing is possible.
viewstate Postback Session
Member
179 Points
149 Posts
Re: Viewstate should never get expired
Jan 12, 2015 10:22 AM|sumeetssm|LINK
hi AidyF,
nice to see you again,
no, nothing is happening, as i have shared little code earlier,
I will elaborate it once again,
1] i want the AdminFlag to be retained, the viewstate to be retained.
2] if the user keeps the page open on his/her browser, again opens the tab and clicks the refresh data button, only the data in the grid should get refreshed as the user has already selected other details from the dropdowns.(I have few selection fields like dropdown and date and a refresh button that refreshes the data)
3] Once done with this logic, i have to apply this logic all over my web application!.
I do have a function
This code i fire later on, so i feel it has no effect, the first thing is i should get adminflag in the second line for the former statements.
Please help.
viewstate Postback Session
Please mark as answer if helpful