Persistent Controls

Some controls are used for the purpose of controlling how a form looks, rather than for the purpose of entering data in a database. If the user is navigating back and forth between various forms, it can be very frustrating to have to manually change the controls to the previous values just to get back to the data you were viewing.

For example, if you have a DataGrid showing multiple pages, and the user is on page 3, and then clicks on an item to edit it, and then saves or cancels, your application should take the user back to page 3 of the DataGrid, and not page 1, the default.

To get a control to restore its prior state, simply set its SaveState attribute to true. The control will automatically be set to its previous state. Generally, you would only do this for controls that are not getting data directly from the database, but rather controls that change how data is viewed. A good example would be a text box you use to filter a list.

The state data of the control is saved in the session by default in a variable named the configuration constant QCUBED_SESSION_SAVED_STATE (the default value is 'QSavedState'). If your application has authenticated users who can see private data, you can serialize the contents of this session variable and store it in your database with the user's credentials, and then restore it on the next login. The user will then see your application in the same state as before. The data stored in the session variable is only necessary to restore the visual state of the control and takes up very little space.

In the example here, you will see two sets of controls. One has SaveState turned on, and the other does not. When you click on the "Reload the Page" button, you will notice that the controls with SaveState set to true do not change, but the other controls revert to their default values.

Note on Usage

The moment that you set SaveState to true, QCubed-4 will look for a previously saved state and restore it if one is found. So, if you would like to set your control to a particular default value, do that before you set SaveState to true.

SavedState = false

SavedState = true