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.
我有一个asp.net页面里面有一个multiview控件。在控件中有许多文本框,选择和动态创建的表。因此,我相信我必须在每个回发上使用viewstate。但是,我担心页面大小会增加并且会减慢重新加载时间。所以,我正在考虑将viewstate移动到数据库中。方便吗?还是有其他方法可以解决这个问题。
Thanks in advance
提前致谢
2 个解决方案
#1
1
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.
第二,你真的需要这么多的回帖吗?你可以改为写一个ajax调用,不会用回发来吹走页面吗?这样做有助于改善用户体验并减少视图状态中所需的元素数量。
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.
在开始之前,我会坐下来考虑这个页面的设计。如果它是一个臃肿的抓住所有页面,也许你需要创造性地实现它如何为用户提供良好的体验。
#2
0
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.
首先,viewstate是旧技术,但如果你必须使用“经典”ASP.NET方法,那么你回答的是尝试关闭不需要持久化状态的控件的viewstate,这样就是标签控件,你应该只是文本和如果你有这样的选择,其次将它移动到状态服务器。
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. :) :)
如果您继续优化,请查看MVC3 http://www.asp.net/mvc + JQuery + Ajax。大型项目是通过这样的技术完成的,例如这个网站就是这样。 :) :)