Last post Jul 01, 2005 08:35 PM by c23chaos
Jul 01, 2005 03:56 PM|c23chaos|LINK
Jul 01, 2005 05:24 PM|billrob458|LINK
Jul 01, 2005 05:47 PM|c23chaos|LINK
Jul 01, 2005 06:45 PM|billrob458|LINK
Jul 01, 2005 07:33 PM|c23chaos|LINK
Jul 01, 2005 08:01 PM|billrob458|LINK
The easiest way I have found to use Session or ViewState is wrap you field into a property
Private ReadOnly Property CollTypeLabels() As SortedList
Dim list As SortedList = CType(ViewState.Item("CollTypeLabels"), SortedList)
If list Is Nothing Then
list = New SortedList
All references in your code to m_CollTypeLabels should be replaced by this property. Infact, you can remove the m_CollTypeLabel fields just to make sure you don't have any lingering ones.
When you call the get on the property, such as when you try to add an item. The getter will pull the item from ViewState, it ofcourse will be nothing. A new SortedList is created and stored into ViewState, then it is returned.
The next time (and even on the next postback) you try to reference your list, it will be pulled from ViewState, this time it will not be null and the List will be returned directly.
Using a property encapsulates this away so you can change from Session to ViewState in only one section of your code and the implementation details are hidden from the usage of the object.
Jul 01, 2005 08:35 PM|c23chaos|LINK