Prev | Current Page 286 | Next

Rob Cameron and Dale Michalk

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

The ViewState rendered by the control into this web form shows the Text
property as a blank value. We entered a name into the TextBox as well, but we haven??™t clicked
the button to submit the web form via postback.
Figure 5-5. Initial rendering of the TextBox control
CHAPTER 5 ?–  SERVER CONTROL EVEN TS 197
Upon clicking the button to execute a postback to the web server, the TextBox control will
read the blank value from ViewState and find the name value ???Rob??? when the ASP.NET invokes
LoadPostData. Because the posted data is different from the current ViewState value, it calls its
internal OnTextChanged method to raise events to all registered delegate subscribers. This results
in the Name_TextChanged event handler method firing, and the code that changes the label to
reflect the new value executes:
private void Name_TextChanged(object sender, System.EventArgs e)
{
ChangeLabel.Text = DateTime.Now.ToLongTimeString() + ": Changed!";
}
The result is that ChangeLabel displays the text containing the current time and the word
???Changed!??? as shown in Figure 5-6.
Figure 5-6. The TextBox control fires the TextChanged event.
The next step in this demonstration is to recycle the page without changing the value in
the TextBox control by simply clicking the Submit Page button.


Pages:
274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298