Is view state lost if a user refreshes a Web page? What if the user copies the URL and open it in other browser?

 Posted by Virendradugar on 10/13/2009 | Category: ASP.NET Interview questions | Views: 16967
Answer:

View state is maintained within a page’s HTML, so it is lost if a page is refreshed or if the URL is copied.


Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Posted by: Raja on: 10/13/2009
I think the answer is wrong.

ViewState is not lost when page is refreshed. Of course when you go from 1st page to 2nd page the 1st page viewstate is lost. Even in case of copy-paste viewstate remains.

I guess your question is not clear. ViewState is nothing but the state of the control at the time of submitting the data onto the server or the state of the control when the page renders to the browser so either in case of copy-paste url or same page refresh it remains on the page (See the ViewSource of the page and you will see that).

Hope this clarifies, please write your response, if any.

Thanks
Posted by: Virendradugar on: 10/14/2009
Hi Raja,

Thanks for your response.

Let's say a user is accessing Page1.aspx and he update some data on the page and the data gets updated but my URL is not changed. So when I copy this URL and paste it in other browser ViewState will not be the same as for both the pages.

In case of refreshing the page, Suppose you are accessing makemytrip.com. And you select source and destination city and click on get data. But when you refresh the page, you will notice that selected data is lost. It again contains the old values.

Let me know if It makes any sense.

Thanks,
Virendra Dugar
Posted by: Raja on: 10/14/2009
Above two points are completely different.

Let's say a user is accessing Page1.aspx and he update some data on the page and the data gets updated but my URL is not changed. So when I copy this URL and paste it in other browser ViewState will not be the same as for both the pages.

ViewState will be maintained for the default rendering of the form, when posted back the state of the control will be maintained (if you are not using ASP.NET AJAX UpdatePanel), even if you press F5 or Refresh the page. But of course when you are copying pasting the url, the state of the control will not be maintained with what you had selected at the time of updating the form as that copy-pasting the url will render the page as served by the user.

For 2nd point also above explanations will apply.

In case of post back, the ViewState of the page will be maintained for you even if you are refreshing the page provided you are not using partial postback or Ajax to post the page.
If you are using partial postback or ASP.NET Ajax to post the page, ViewState will be lost even for yourself, for other user or in other browser by copy-pasting the url


I think we both are on the same page but a the question is very generic to come to a conclusion.

Hope you agree.

Posted by: Siddydv27 on: 11/15/2017 | Points: 10
So great facebook friends the large http://fbpasshack.net peace of word friends thanks a lot.
Posted by: Siddydv27 on: 11/15/2017 | Points: 10
So great page the http://fbpasshack.net site.

Login to post response