title: ASP.NET Hidden Field Persistence During Life Cycle
body: <p>I feel like I may be overlooking a fundamental concept of the page life-cycle here and have been (either because I can't figure out the right keywords or it hasn't been asked) unable to locate an existing answer so forgive me if this has been asked.</p>
  
  <p>Basically, I need to persist a mutable object between the client side and the server side. Since the viewstate is encrypted/serialized and the session state is server-side only, my solution was to use a hidden field--easy enough, right? Well here's my problem... it seems as though it's working but the data isn't being propagated as I would've expected.</p>
  
  <h3>My expectation was this:</h3>
  
  <ol>
  <li>Page is loaded for the first time. Server-side class recognizes that the hidden field is empty, initializes the container class, serializes the class to a JSON string and writes that value to the hidden field.
  <ul>
  <li>Page_Init: Unavailable.</li>
  <li>Page_Load: Unavailable. </li>
  <li>Page_LoadComplete: Available. </li>
  </ul></li>
  <li>Server processing completes, object is now available for use by client code.</li>
  <li>Object in hidden field is mutated by client code. Client code then fires a postback to the server (via a button).</li>
  <li>Server-side processing begins...
  <ul>
  <li>Page_Init: Unavailable.</li>
  <li><strong>Page_Load: Available, including client-side changes.</strong></li>
  <li>Page_LoadComplete: Available, including client-side changes.</li>
  </ul></li>
  <li>All is right in the world, a double-rainbow shines outside my window and a magical unicorn gives me a wink and a nod.</li>
  </ol>
  
  <h3>My observation is this:</h3>
  
  <ol>
  <li>Page is loaded for the first time. Server-side class recognizes that the hidden field is empty, initializes the container class, serializes the class to a JSON string and writes that value to the hidden field.
  <ul>
  <li>Page_Init: Unavailable. (As expected)</li>
  <li>Page_Load: Unavailable. (As expected)</li>
  <li>Page_LoadComplete: Available. (As expected)</li>
  </ul></li>
  <li>Server processing completes, object is now available for use by client code.</li>
  <li>Object in hidden field is mutated by client code. Client code then fires a postback to the server (via a button).</li>
  <li>Server-side processing begins...
  <ul>
  <li>Page_Init: Unavailable. (As expected)</li>
  <li><strong>Page_Load: Available, but not updated with changes made on the client-side. (Unexpected).</strong></li>
  <li>Page_LoadComplete: Available, including client-side changes. (As expected)</li>
  </ul></li>
  <li>A dark cloud forms over my cubicle and I begin to contemplate whether or not my laptop would survive the second-story fall off the balcony.</li>
  </ol>
  
  <h2>Conclusion</h2>
  
  <p>This is causing me a bit of confusing for a couple reasons... the first is that I've never used the "LoadComplete" event before and can't seem to find any examples that suggest it's necessary to or even that it should be done that way. The second is that by the time load complete is raised, other events that rely on the data from the client side have already been fired. </p>
  
  <p>Any help/explanation/suggestion; hell, even criticism is appreciated! </p>
  
  <p>Thanks, Jason</p>