Closed and Collapsed state not loading

8 posts, 1 answers
  1. Sam
    Sam avatar
    103 posts
    Member since:
    Feb 2009

    Posted 06 May 2009 Link to this post

    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



  2. Obi-Wan Kenobi
    Obi-Wan Kenobi  avatar
    460 posts
    Member since:
    Aug 2007

    Posted 07 May 2009 Link to this post

    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.
  3. Sam
    Sam avatar
    103 posts
    Member since:
    Feb 2009

    Posted 07 May 2009 Link to this post

    Thanks for the reply, where in my code would I do this? Page_Init?
  4. Answer
    Obi-Wan Kenobi
    Obi-Wan Kenobi  avatar
    460 posts
    Member since:
    Aug 2007

    Posted 11 May 2009 Link to this post

    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 

  5. Sam
    Sam avatar
    103 posts
    Member since:
    Feb 2009

    Posted 11 May 2009 Link to this post

    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 
  6. Sam
    Sam avatar
    103 posts
    Member since:
    Feb 2009

    Posted 11 May 2009 Link to this post

    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.

  7. Sam
    Sam avatar
    103 posts
    Member since:
    Feb 2009

    Posted 11 May 2009 Link to this post

    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
  8. Martin
    Martin avatar
    84 posts
    Member since:
    Apr 2009

    Posted 18 Jun 2009 Link to this post

    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

Back to Top