Congratulations to all the winners of April 2013, they have won INR 3400 cash and INR 20147 worth prizes !
DotNetFunda.Com Logo
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 2093 |  Welcome, Guest!   Register  Login
 Home > Interview Questions > ASP.NET Interview Questions > Is view state lost if a user refreshes a ...

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

Interview question and answer by: Virendradugar | Posted on: 10/13/2009 | Category: ASP.NET Interview questions | Views: 6699 |


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 
Found interesting? Add this to:


 Responses

Posted by: Raja | Posted on: 13 Oct 2009 11:20:48 PM | Alert Moderator 

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 | Posted on: 14 Oct 2009 01:32:15 AM | Alert Moderator 

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 | Posted on: 14 Oct 2009 03:48:49 AM | Alert Moderator 

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.


>> Write Response - Respond to this post and get points

Even more ... | Submit Interview Questions and win prizes!

More Interview Questions from Virendradugar

Even more ... | Submit Interview Questions and win prizes!


About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/19/2013 5:43:28 PM