解决方法
它是这样的:
Why some controls retain values
even after disabling the ViewState
while others do not?The answer is Controls which
implementsIPostBackEventHandlerIPostBackDataHandler like
TextBox,CheckBox,etc. will retain
the state even after disabling the
viewstate. The reason is during the
Load Postback Data stage,these
controls will get state information
from Posted back form.But controls like label which do not
implementIPostBackEventHandlerIPostBackDataHandler will
not get any state information from
posted back data and hence depend
entirely on viewstate to maintain the
state.
以下是与您的问题相关的段落.
In page life cycle,two events are
associated with ViewState:
Load View State: This stage follows the initialization stage of
page lifecycle. During this stage,
ViewState information saved in the
prevIoUs postback is loaded into
controls. As there is no need to check
and load prevIoUs data,when the page
is loaded for the first time this
stage will not happen. On subsequent
postback of the page as there may be
prevIoUs data for the controls,the
page will go through this stage.Save View State: This stage precedes the render stage of the page.
During this stage,current state
(value) of controls is serialized into
64 bit encoded string and persisted in
the hidden control (__ViewState) in
the page.Load Postback Data stage: Though this stage has nothing to do with
ViewState,it causes most of the
misconception among developers. This
stage only happens when the page has
been posted back. ASP.NET controls
which implementIPostBackEventHandlerIPostBackDataHandler
will update its value (state) from the
appropriate postback data. The
important things to note about this
stage are as follows:
- State (value) of controls are NOT retrieved from ViewState but from
posted back form.- Page class will hand over the posted back data to only those
controls which implement
IPostBackEventHandlerIPostBackDataHandler.- This stage follows the Load View State stage,in other words state of controls set during the Load View State stage will be overwritten in this stage.