2007年10月30日星期二

ViewState and Postback

You can selectively turn off ViewState processing for an entire ASP.NET page or for
individual controls. You do this by setting the EnableViewState property of the
document or the control to False. Storing the ViewState is necessary only if a page
posts back to itself. You should turn off ViewState if a page posts its information to
another page, because the ViewState values won't do any good there.
Remember, too, that the information stored in ViewState is sent to the server and
back every time you post a page. Although the information is compressed, it still
represents additional bulk (and thus delay) for loading the page. ViewState is not a
good choice for storing huge amounts of information.
When you're considering the amount of data that gets moved around, you need to
remember to check the AutoPostBack properties of your controls. If every control on
your form has AutoPostBack set to True, and ViewState is enabled throughout,
then you'll be sending the most possible data every time the focus changes on your
form. This is ve ry likely to slow down your application. You should reserve the
AutoPostBack setting of True for controls where you need to trap events while the
user is still working with the page and before they've submitted it back to the server.

没有评论: