What User State Information to Save?
As coded so far, the PublishersWebUI project requires no user state information to be saved, so let's add some. Recall that this sample allows the user to use a Search Publishers form to search for authors found in the ubiquitous Biblio.mdb database. One piece of state information you may remember is the search string the user entered. This way, we can repopulate the filter text box with the last search string they used whenever they return to the search form from another page.
Storing the search filter value as a single string is pretty trivial, so let's complicate things a bit by enhancing the application to allow the user to add authors to a "Selected Authors List." We can also give them an option to view all the authors they have added to the list. This is generally the same type of processing used in e-commerce sites that allow users to search for products and then select items to place in an electronic "shopping cart."
Our design suggests that we should add properties to clsUserState for any user state information we need to save. For the search string filter text, we can simply declare a Public variable of type String. Storing selected publishers is more complicated because at any time our user's state might contain zero, one, or many selected publishers. To allow multiple publishers to be retained, I created a tiny clsPubState class to hold the necessary information about the publishers that have been selected and then exposed a Publishers Collection object from clsUserState to hold references to clsPubState objects. In my example, the "View Selected Publishers" page displays the publisher name and telephone number. It also contains a hyperlink to the Publisher Details page, so it must also include the Publisher ID.
Here's the entire code contents of clsPubState:
Option Explicit Public PubID As Long Public Name As String Public Phone As String
And here's the new General Declarations section from clsUserState:
Option Explicit Public Filter As String Public Publishers As Collection Private mUserID As String