Thursday, 16 June 2011

State, still

How we want to see it working:

a. User requests page
b. Page is sent to user
c. User clicks buttons, page handles events


How it is working in reality:

a. User requests page
b. Page is sent to user and discarded
c. User clicks buttons, new page handles events




How to make the reality look like a dream:

1. Get the data from the database and render dynamic controls in Page_PreRender 
2. Save the data which is used to render controls between requests in a ViewState
3. When user submits the page back to server (Page.IsPostback == true), recreate controls as they were, from the ViewState
4. Happily handle all the events
5. Discard all restored controls in Page_PreRender and start all over again.



As I understand, this is how (more or less) databound server controls are working.

No comments:

Post a Comment