Keeping ViewState in SessionPageStatePersister

后端 未结 4 1429
情书的邮戳
情书的邮戳 2020-12-16 01:52

I want to keep viewstate of a specific page in session but following code block does not help me, what might I be missing?

So here is the code-behind file content of

4条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-16 02:36

    Note that even after you move the page state to view state, you will still see a __Viewstate element on your pages.

    Also, I believe that this solution may be more correct than the others offered, as it handles the back button a bit more elegantly. When you store the ViewState in a hidden variable, it becomes part of the HTML, and is therefore available if the user clicks the back button 2 or 3 pages and continues with what he was doing. Blindly trashing the Viewstate with each page request will prevent the back button from behaving the way the user is expecting.

    However, it would be remiss to note that this is probably not a great idea in the first place. I would suggest doing at least two things first:

    First, make sure that you have turned off Viewstate on all of the controls that don't need it (which will probably be most of them). You can do this by setting 'IsViewstateEnabled' to false.

    Second, turn on http compression on your webserver. Even if you have a reasonably sized viewstate, the total page weight (when compressed - not as viewed in your browser) should be relatively small.

    Hope that helps!

提交回复
热议问题