This is one of those posts that pains me to write. I blame Monorail for the pain that I am now acutely aware of in working with the Web Forms model in ASP.NET. But that's a whole other post...
Dealing with the events that take place in the lifetime of a Page in WebForms is tricky once you get beyond the demo samples. Dynamic loading of controls based on state, collection control (ie, Repeater) value persistence between postbacks, and event timing of web controls immediately reveal to the excited "look I can drag a GridView and see my employees table" developer that he has just stepped in a big pile of over-architecture and got bizarre form behavior all over him.

And that is with ViewState ON.
A wise blogger once wrote ViewState is the devil and shortly after that I was checking out Scott Watermasysk's ASP.NET tips and dealing with bloated pages in my own application...I was encouraged to turn ViewState OFF and deal with the consequences. I really HAD to since my ViewState had gotten out of control.
As if that didn't complicate matters enough, I was using the Model-View-Presenter pattern and wrestled with how to implement this with a stateless view (more or less) that has a complex strategy for restoring values from the Request.Form collection while making the view the entry point for requests, thus seemingly forcing my Presenter/Controller into submission to the famed ASP.NET Page Lifecycle...something I was hoping to avoid.
I decided it was time to just isolate all this and create a test bed where I could discover exactly what is happening when with actual controls and get feedback from this monster to tell me what it demands for me to simply pass data back and forth in a text stream. So I created this simple project that has quite a bit of sample data and different ways to see events firing during the postbacks. Controls like the Repeater and DropDownList are absolutely non-intuitive once ViewState is OFF and so are worth a close look on how to persist values. Also, the event handling of simple controls like the TextBox require some deeper understanding once you turn ViewState off.
I simply had quite a bit of difficulty finding actual code that showed things happening at different times when I was first swimming in the sea of events ASP.NET offers...all I could find were pretty diagrams and lots of code jammed in Page_Load with the occasional exotic mention of the 'catch-up' performed by controls upon Controls.Add to the control hierarchy.
So for this first post, here is the project .
DISCLAIMER: It's not pretty, but rather could maybe be useful for people who are confused about what is happening in their pages or to teach others.
I have since settled down quite a bit regarding how I prefer to implement MVP since I created this. I'll post more on what I do with MVP in the future.
Posted
10-04-2007 1:04 AM
by
Michael Nichols