viewstate in database? is it convenient?
I've an asp.net page which there is a multiview control inside. Within the control 开发者_高级运维there are many many textboxes, selects and dynamically created tables. Therefore, I believe I have to use the viewstate on each postback. However, I'm afraid that the page size will increase and will slow down the reload time. So, I'm thinking to move the viewstate in a database. Is it convenient? Or are there any other ways to overcome this problem.
Thanks in advance
For a page such as the one you're describing you need to ask yourself a few things.
First, do you need to save the state of all the controls? Probably not. For controls you won't need to remember the state of, turn the viewstate off for them.
Second, do you really need so many post backs? Could you instead write an ajax call that won't blow away the page with a postback? Doing this will help improve your user experience as well as reduce the number of elements needed in your viewstate.
Third, for dynamically created controls, you will need to manage the objects yourself anyway so you might as well turn viewstate off for them.
To answer your actual question, no storing your view state in a DB is not a good idea. That will slow down your page and will over complicate things to the extreme. If two people are on your page, how are you going to make sure there isn't cross contamination? How many people will be hitting this page? What would you index that table one to keep it from being stupid slow? See...complex already.
I would sit down and think about the design of this page before going forward. If it's a bloated catch all page, perhaps you need to get creative with how you implement it to give your users a good experience.
First of all viewstate is old technique, but if you must use "Classic" ASP.NET methodologies then yeah you answer is try turn off viewstate on controls that do not need persisting state, such would be label controls where you are just should text and secondly move it to a state server if you have such option.
If you are keep on optimising such have a look at MVC3 http://www.asp.net/mvc + JQuery + Ajax. Large projects are done with such technologies, one for example is this very site. :) :)
精彩评论