I've read somewhere that events of ASP .NET are based on View State of ASPX page. The values of submitted controls are matched with their value of view state and if any difference is found then t开发者_C百科he corresponding event is called up.
But my question is: "When events are really based on view state than why events are fired even when the view state is disabled using EnableViewState=false."
Thanks, Guru.
If you really want to understand ViewState, go through this article...
http://weblogs.asp.net/infinitiesloop/archive/2006/08/03/Truly-Understanding-Viewstate.aspx
And this one is official @ msdn... http://msdn.microsoft.com/en-us/library/ms972976.aspx
What I can say is... try going through the first link that I have just shared... and by the end of that article you will have all your queries answered. I consider it the best article available on this subject.
The short answer is... the events will always be there since that is how the page lifecycle should be... in a specific order! And that is regardless of the viewstate being on or off.
ViewState is only incidentally related to ASP.NET events. A better way of phrasing this would be that the values of the submitted controls are matched with corresponding controls found after re-constructing the page. A page is re-constructed based on a combination of both ViewState and the original layout of the page as defined in the code-front. (not to mention that controls can be created server-side within the CreateChildControls
virtual method in either your own pages/controls, or 3rd party custom controls)
So as for your question, my guess is that the events are being fired because the controls firing the events were not state-based -- they are statically defined in the code-front and are always available.
In contrast, some controls are created on-the-fly. For example, if you use a Repeater
in combination with an ItemTemplate
, you could put a button inside the item template. The items in a repeater are dependent on the values in its DataSource, not the code-front. Therefore, if you were to disable ViewState in this scenario, you would indeed mess up the event handling.
精彩评论