Custom object Collections and ViewState
-
Does anyone know of an example or have some sample code for saving a Class object derived from CollectionBase containing Custom Class objects? Derek Spurlock Spursoft Solutions
Hi, I dont know if this is unworkable for you or not, but here is how i addressed this problem. I thought about making my class so it would support serialization and all to be easily savable to the viewstate, but then i realized... if you serialize you collection out to the viewstate, then with each transmission back and forth, the page will be retransmitting the whole collection of data. So instead, i stuck my collection in a session variable. Then, to make it easy to access i created a property on my pages so they could just reference
Me.MfgList
which would return the list. So here is my code in abbreviated form:Public Class AppPageBase Inherits System.Web.UI.Page Protected Readonly Property MfgList As clsMfgList Get Return CType(Session("mfglist"),clsMfgList) End Get End Property End Class
Then all my pages inherit from AppPageBase instead of from System.Web.UI.Page directly. You can load your list into the session variable in the Session_OnStart event in global.asax. This same method is a great way to provide easy access to lots of other app-specific custom data.