I've spent many days in the past week trying to find a good way to make custom docks and store the config in a database. Most of that time was on this forum, going through other people's posts who were fighting the same issues. I also downloaded some of the other samples, and most were very complex, and I never got even one of the examples to work. So, I started from scratch, using the Portal Demo as the example. In order to save others the rough week I had, I'm posting my solution here.
Download the dynamically created controls portal example: http://www.telerik.com/demos/aspnet/prometheus/Dock/Examples/MyPortal/DefaultVB.aspx
All I did was add some script to the CurrentDockStates property to save a value on a SET command and retrieve a value on a GET command if no value was already present. It works like a champ. Hope this helps. Here's my new CurrentDockStates property.
Enjoy,
- Brad
Download the dynamically created controls portal example: http://www.telerik.com/demos/aspnet/prometheus/Dock/Examples/MyPortal/DefaultVB.aspx
All I did was add some script to the CurrentDockStates property to save a value on a SET command and retrieve a value on a GET command if no value was already present. It works like a champ. Hope this helps. Here's my new CurrentDockStates property.
Enjoy,
- Brad
| Private Property CurrentDockStates() As List(Of DockState) |
| Get |
| Dim _currentDockStates As List(Of DockState) = DirectCast(Session("UserPreferences.PortalSession"), List(Of DockState)) |
| If [Object].Equals(_currentDockStates, Nothing) Then |
| 'Make an empty configuration list |
| _currentDockStates = New List(Of DockState)() |
| 'Convert our stored config to the active config |
| ''I HAVE A FUNCTION THAT GETS THE USER'S DOCKSTATE STRING FROM A |
| '' TABLE IN THE DATABASE CALL GetUserPreference |
| '' INSERT WHATEVER DATABASE ROUTINE YOU WANT IN PLACE OF IT |
| Dim strLoadedConfig As String = GetUserPreference("PortalConfiguration") |
| 'If we found nothing, leave the current state empty |
| If strLoadedConfig <> "" Then |
| Try |
| 'Use the stored config |
| 'Convert the stored config to an array, splitting at the *s |
| Dim aConfig As Array = Split(strLoadedConfig, "*") |
| Dim strConfigItem As String |
| Dim dsWorking As DockState |
| 'Parse through the array, turning the dockstate strings into dockstates |
| 'Then add the dockstates to the dockstate list |
| For Each strConfigItem In aConfig |
| 'Start a fresh dockstate |
| dsWorking = New DockState |
| 'Parse the string back into dock settings |
| dsWorking = DockState.Deserialize(strConfigItem) |
| 'Add the settings back into the current session |
| _currentDockStates.Add(dsWorking) |
| Next |
| Catch ex As Exception |
| 'Something was wrong with the data |
| 'Default back to blank so the page won't crash |
| End Try |
| 'Set the new value into the session variable |
| Session("UserPreferences.PortalSession") = _currentDockStates |
| End If |
| End If |
| Return _currentDockStates |
| End Get |
| Set(ByVal value As List(Of DockState)) |
| Session("UserPreferences.PortalSession") = value |
| 'Session being updated; Update the database too |
| 'Convert list of dockStates to a delimited string |
| 'We'll use * since commas are used in the dockStates |
| Dim sbListConverter As New System.Text.StringBuilder |
| For Each dockState As DockState In value |
| sbListConverter.AppendFormat("{0}*", dockState.ToString) |
| Next |
| Dim strDockConfig As String = sbListConverter.ToString.TrimEnd(Convert.ToChar("*")) |
| ''I HAVE A FUNCTION THAT SAVES THE USER'S DOCKSTATE STRING TO A |
| '' TABLE IN THE DATABASE CALLED UpdateUserPreference |
| '' INSERT WHATEVER DATABASE ROUTINE YOU WANT IN PLACE OF IT |
| '' SAVE IN A LARGE ENOUGH TEXT FIELD [varChar(MAX)?] TO HOLD |
| '' ALL THE STATE INFO |
| 'Save string to database |
| UpdateUserPreference("PortalConfiguration", strDockConfig) |
| End Set |
| End Property |