Prev | Current Page 173 | Next

Rob Cameron and Dale Michalk

"Pro ASP.NET 3.5 Server Controls and AJAX Components"

Not until the next roundtrip
to the server does ASP.NET have a chance to access the current state and populate the
fields at the bottom of the page. The reason for this is that when you click Set State, the Page_Load
event fires first, which executes the GetClientState() helper method. GetClientState() loads
100 CHAPTER 3 ?–  ASP.NET S TATE MANAGEMENT
the current values from the various state storage mechanisms into the labels on the bottom
portion of the web form. Because the server-side click event SetStateButton_Click has not
had a chance to fire just yet, the state loaded into the fields at the bottom of the web form by
GetClientState() in Page_Load is the previous state, as shown in Figure 3-4. After the Page_Load
event completes, SetStateButton_Click executes next, calling SetClientState(), which loads
the value from the TextBox control into all the client-state mechanisms. The resulting page
shows that all the state mechanisms are storing the value.
Now that the state has been set, clicking the Submit button one more time forces a roundtrip
to the server, executing the Page_Load event. This time around, the fields at the bottom of
the page have a chance to pick up the current state in GetClientState() and display the expected
values.


Pages:
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185