Reputation: 2758
Upon page reloads I want to retain the values the user had typed in upon hitting submit.
I worry about viewstates being cumbersome for pages, both in bandwidth and in time for a page viewer to download the page. I am cheap with my bytes :p
My question is instead of using server controls and such I am having the form on the page do a get to itself and on the aspx putting
<input type="text" id="user_email" name="email" value="<%=Request.Form["email"] %>" />
This allows me to not use viewstate. Are there any potential shortcomings to doing things this way? My goal is always for a lighter page and efficiency even if it is more work.
Thanks in advance
Upvotes: 1
Views: 986
Reputation: 95
You can solve this using 0 bytes of ViewState data sent to the clients with very little work and with no changes to your existing code: Storing the ViewState on server's file system.
Read more about it here: https://msdn.microsoft.com/en-us/library/ms972976.aspx .
You don't have to read it all, scroll down until you reach the chapter Specifying Where to Persist the View State. All you need to do us inherit the Page class used in your pages, override certain ViewState- related methods for changing ViewState behaviour. Example code is in the link.
Hints
You should definitly use SSD storage for this kind of ViewState. On an Azure server the D: Temp- drive is optimized for this type of use.
For further performance, you could implement a cache- mechanism that primarely uses System.Web.Caching instead of SSD. But only write to SSD when memory is full and cache is about to be wiped. Read more about caching here under Caching API, Using the Cache object: https://msdn.microsoft.com/en-us/library/aa478965.aspx
If you choose to use Caching, you should also remove the old ViewState from the Cache whenever the same user posts the next time. That would significantly remove memory consumption and probably eliminate need for SSD- write overall most of the time.
Set a reasonable amount of time to persist the ViewState. On most kinds of pages, 30 min - 1 hour should do be enough.
Please ask me if you want further examples. :)
Upvotes: 0
Reputation: 116
This could be a lot of work and it might bite you later if you want to do this work around. I would recommend you disable the viewstate on the page or control basis otherwise I think there is no point of using ASP.NET webform, you might want to try looking at ASP.NET MVC Instead.
Upvotes: 1