Control State Basics

  Sample Home | Reset Form
Please enter your name:


Enter a color of your choice:
 




This sample demonstrates the basics of PostBacks and control state preservation. Notice that when this form runs that the data in the textboxes always persists. No code is required to make this happen as Web Connection automatically repopulates all post back controls on the form.

However, notice that the message label and the color options will not persist across button clicks. If you click Say Hello and a color is set on the button, the color is lost. If you click on Set Color and a message is set, the message is lost. This is because labels and captions - just about any attribute of controls are not posted back to the server, so these values are not automatically persisted back.

To fix, click on the preserve properties checkbox, which fires an event to the server and sets several of the properties we are interested in to persist using the Control.PreserveProperty() method for each of the properties. In this case the label's Text and the button's ForeColor properties.