This is a migrated thread and some comments may be shown as answers.
Closed and Collapsed state not loading
7 Answers 53 Views
This is a migrated thread and some comments may be shown as answers.
Sam
Top achievements
Rank 1
Sam asked on 06 May 2009, 01:35 PM
I am saving the state of the Radodocks in a database and when I collapse a dock I can see the correct state being saved to the table but when I reload the page it doesn't come back collapsed and the state field in the table gets overwritten with collapsed: false..... here is my code.

Save

Protected Sub RadDockLayout1_SaveDockLayout(ByVal sender As Object, ByVal e As Telerik.Web.UI.DockLayoutEventArgs)
        'Save the dock state in the session. This will enable us to recreate the dock in the next Page_Init.
        CurrentDockStates = RadDockLayout1.GetRegisteredDocksState()
    End Sub


Load

Protected Sub RadDockLayout1_LoadDockLayout(ByVal sender As Object, ByVal e As Telerik.Web.UI.DockLayoutEventArgs)

        Dim _currentDockStates As New List(Of DockState)()
        Dim ContactID As Integer = Int32.Parse(Utilities.GetSession("ContactNumber").ToString())
     
        _state = PortalDataAccess.LoadState(ContactID).ToString()
   

        Dim dockStates As String() = _state.Split("|"c)

        For i As Integer = 0 To dockStates.Length - 1
            Dim serializedState As String = dockStates(i)
            If Not String.IsNullOrEmpty(serializedState) Then
                Dim state As DockState = DockState.Deserialize(serializedState)
                _currentDockStates.Add(state)
            End If
        Next

        For Each state As DockState In _currentDockStates
            e.Positions(state.UniqueName) = state.DockZoneID
            e.Indices(state.UniqueName) = state.Index
        Next

    End Sub

Thanks,
Sam



7 Answers, 1 is accepted

Sort by
0
Obi-Wan Kenobi
Top achievements
Rank 1
answered on 07 May 2009, 09:53 AM
You should invoke dock.ApplyState(state); when you recreate RadDocks.
Keep in mind that when you collapse, expand or close a RadDock you should create one additional ajax/postback to save the new state into the DB.
0
Sam
Top achievements
Rank 1
answered on 07 May 2009, 07:53 PM
Thanks for the reply, where in my code would I do this? Page_Init?
0
Accepted
Obi-Wan Kenobi
Top achievements
Rank 1
answered on 11 May 2009, 10:52 AM
In  RadDockLayout1_LoadDockLayout, e.g.
For Each state As DockState In CurrentDockStates  
    e.Positions(state.UniqueName) = state.DockZoneID  
    e.Indices(state.UniqueName) = state.Index  
    Dim dock As RadDock = DirectCast(RadDockLayout1.FindControl(state.UniqueName), RadDock)  
 
    dock.ApplyState(state)  
Next 

0
Sam
Top achievements
Rank 1
answered on 11 May 2009, 01:32 PM
Thanks for the reply, it still isn't loading the Correct Closed and Collapsed state. It's getting over written in the database before it loads so I am assuming Save is firing and over writing it because just before I load the page the second time I am looking at the state field in our database and its correct. Here is the entire code behind.  I've been messing with this for a week or so, if anyone can help solve this I'd greatly appreciate it.


Imports System  
Imports System.Collections.Generic  
Imports System.Data.SqlClient  
Imports System.Web.Script.Serialization  
Imports System.Collections  
Imports Telerik.Web.UI  
 
Partial Class portal  
    Inherits System.Web.UI.Page  
 
    Private _state As String  
 
 
    Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init  
        Dim RoleID As Integer  
        Dim drContacts As SqlDataReader  
        Dim control As New Web.UI.Control()  
        Dim count As Integer = 0 
        RadDockZone1.Controls.Clear()  
        RadDockZone0.Controls.Clear()  
        Dim Edit As String = Utilities.GetSession("Edit Layout Allowed")  
        RoleID = Int32.Parse(Utilities.GetSession("PortalRoleID"))  
        drContacts = PortalDataAccess.GetPortalControlsByRoleID(RoleID)  
        If (drContacts.HasRows) Then  
            While (drContacts.Read())  
                Dim soRadDock As New RadDock()  
                soRadDock.ID = drContacts("ControlID").ToString()  
                soRadDock.Title = drContacts("ControlTitle").ToString()  
                control = LoadControl("UserControls/" & drContacts("ControlName").ToString() & ".ascx")  
                soRadDock.ContentContainer.Controls.Add(control)  
                If drContacts("Zone") = 1 Then  
                    CreateSaveStateTriggers(soRadDock)  
                    'soRadDock.ApplyState(state)  
                    RadDockZone1.Controls.Add(soRadDock)  
 
                End If  
 
                If drContacts("Zone") = 0 Then  
                    CreateSaveStateTriggers(soRadDock)  
                    'soRadDock.ApplyState(state)  
                    RadDockZone0.Controls.Add(soRadDock)  
 
                End If  
 
            End While  
 
            drContacts.Close()  
        End If  
 
    End Sub  
 
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load  
 
        RadDockLayout1.Skin = Application("TelerikTheme")  
        RadDockZone1.Skin = Application("TelerikTheme")  
        RadDockZone1.Skin = Application("TelerikTheme")  
 
 
    End Sub  
 
    Private Property CurrentDockStates() As List(Of DockState)  
 
        Get  
            Dim _currentDockStates As New List(Of DockState)()  
            Dim ContactID As Integer = Int32.Parse(Utilities.GetCookie("PortalContactNumber").ToString())  
            _state = PortalDataAccess.LoadState(ContactID).ToString()  
            Dim dockStates As String() = _state.Split("|"c)  
            For i As Integer = 0 To dockStates.Length - 1  
                Dim serializedState As String = dockStates(i)  
                If Not String.IsNullOrEmpty(serializedState) Then  
                    Dim state As DockStateDockState = DockState.Deserialize(serializedState)  
                    _currentDockStates.Add(state)  
                End If  
            Next  
            Return _currentDockStates  
        End Get  
 
 
 
 
        Set(ByVal value As List(Of DockState))  
            Dim builder As New StringBuilder()  
 
            For i As Integer = 0 To value.Count - 1  
                Dim serializedState As String = value(i).ToString() & "|"  
                builder.Append(serializedState).ToString()  
            Next  
 
            Dim ContactID As Integer = Int32.Parse(Utilities.GetSession("ContactNumber").ToString())  
 
            PortalDataAccess.SaveState(ContactID, builder.ToString())  
        End Set  
 
 
    End Property  
    Protected Sub RadDockLayout1_SaveDockLayout(ByVal sender As Object, ByVal e As Telerik.Web.UI.DockLayoutEventArgs)  
        'Save the dock state in the session. This will enable us to recreate the dock in the next Page_Init.  
        CurrentDockStates = RadDockLayout1.GetRegisteredDocksState()  
    End Sub  
    Protected Sub RadDockLayout1_LoadDockLayout(ByVal sender As Object, ByVal e As Telerik.Web.UI.DockLayoutEventArgs)  
 
        Dim _currentDockStates As New List(Of DockState)()  
        For Each state As DockState In _currentDockStates  
            e.Positions(state.UniqueName) = state.DockZoneID  
            e.Indices(state.UniqueName) = state.Index  
            Dim dock As RadDock = DirectCast(RadDockLayout1.FindControl(state.UniqueName), RadDock)  
            dock.ApplyState(state)  
        Next  
 
    End Sub  
End Class 
0
Sam
Top achievements
Rank 1
answered on 11 May 2009, 02:47 PM
When I step thru the code in debug It has the correct collapsed state in the Save_Layout sub, could it be that I am calling createsavestate triggers in Page_Init? Somehow before the page renders it over writes the collapsed state and closed state values to false.

0
Sam
Top achievements
Rank 1
answered on 11 May 2009, 03:17 PM
I fixed it, the Load_Layout sub wasn't Getting the CurrentDockState, I just added a line setting it to the property value and it works now. Thanks for all your help Obi-Wan!

Sam
0
Martin
Top achievements
Rank 1
answered on 18 Jun 2009, 02:07 PM
thanks guys for your help, I had the same problem and

 

RadDock objRadDock = (RadDock)rdltDockLayout.FindControl(state.UniqueName);

 

objRadDock.ApplyState(state);
did it for me:)

too bad the documentation is not overally concerned about the states outside position

Tags
Dock
Asked by
Sam
Top achievements
Rank 1
Answers by
Obi-Wan Kenobi
Top achievements
Rank 1
Sam
Top achievements
Rank 1
Martin
Top achievements
Rank 1
Share this question
or