This is a migrated thread and some comments may be shown as answers.

Docking doesnt save the position

2 Answers 97 Views
Dock
This is a migrated thread and some comments may be shown as answers.
Frank Kocher
Top achievements
Rank 1
Frank Kocher asked on 05 Feb 2010, 05:50 PM
Hi,

i have created a dynamically docking control. At Page_Init (not Postback) I initialize the Docks. But when I move one of the docks every dock is in his start position in the dockingzone after postback, so I can't change the position of the single docks.

ViewState is disabled.

I hope someone can help me. Thx for help.

ascx:
<asp:UpdatePanel  runat="server" ID="UpdatePanel1"
    <ContentTemplate> 
                <rad:RadDockLayout runat="server" ID="RadDockLayout1" OnSaveDockLayout="RadDockLayout1_SaveDockLayout" OnLoadDockLayout="RadDockLayout1_LoadDockLayout" > 
                    <rad:RadDockZone ID="RadDockZoneFelder" runat="server" /> 
                </rad:RadDockLayout> 
                </ContentTemplate> 
  </asp:UpdatePanel> 

 

vb.net:
 
Private Property CurrentDockStates() As List(Of DockState) 
            Get 
                'Store the info about the added docks in the session. For real life 
                ' applications we recommend using database or other storage medium 
                ' for persisting this information. 
                Dim _currentDockStates As List(Of DockState) = DirectCast(Session("CurrentDockStatesDynamicDocks"), List(Of DockState)) 
                If [Object].Equals(_currentDockStates, NothingThen 
                    _currentDockStates = New List(Of DockState)() 
                    Session("CurrentDockStatesDynamicDocks") = _currentDockStates 
                End If 
                Return _currentDockStates 
            End Get 
            Set(ByVal value As List(Of DockState)) 
                Session("CurrentDockStatesDynamicDocks") = value 
            End Set 
        End Property 
 
        Private Sub CreateSaveStateTrigger(ByVal dock As RadDock) 
            'Ensure that the RadDock control will initiate postback 
            ' when its position changes on the client or any of the commands is clicked. 
            'Using the trigger we will "ajaxify" that postback. 
            dock.AutoPostBack = True 
            dock.CommandsAutoPostBack = True 
 
            Dim saveStateTrigger As New AsyncPostBackTrigger() 
            saveStateTrigger.ControlID = dock.ID 
            saveStateTrigger.EventName = "DockPositionChanged" 
            UpdatePanel1.Triggers.Add(saveStateTrigger) 
 
            saveStateTrigger = New AsyncPostBackTrigger() 
            saveStateTrigger.ControlID = dock.ID 
            saveStateTrigger.EventName = "Command" 
            UpdatePanel1.Triggers.Add(saveStateTrigger) 
        End Sub 
 
        Private Function CreateRadDockFromState(ByVal state As DockState) As RadDock 
            Dim dock As New RadDock() 
            dock.DockMode = DockMode.Docked 
            dock.ID = String.Format("radDock{0}", state.UniqueName) 
            dock.Text = state.UniqueName 
 
            'dock.Controls.Add(Me.erzeugeNeuenTabellenEintragFeld(state.UniqueName)) 
 
            dock.ApplyState(state) 
            dock.Commands.Add(New DockCloseCommand()) 
            dock.Commands.Add(New DockExpandCollapseCommand()) 
 
            Return dock 
        End Function 
 
        Protected Sub RadDockLayout1_LoadDockLayout(ByVal sender As ObjectByVal e As DockLayoutEventArgs) 
            'Populate the event args with the state information. The RadDockLayout control 
            ' will automatically move the docks according that information. 
            For Each state As DockState In CurrentDockStates 
                e.Positions(state.UniqueName) = state.DockZoneID 
                e.Indices(state.UniqueName) = state.Index 
            Next 
        End Sub 
 
        Protected Sub RadDockLayout1_SaveDockLayout(ByVal sender As ObjectByVal e As DockLayoutEventArgs) 
            'Save the dock state in the page Session. This will enable us 
            ' to recreate the dock in the next Page_Init. 
            CurrentDockStates = RadDockLayout1.GetRegisteredDocksState() 
        End Sub 
 
        Protected Sub RadDock1_DockPositionChanged(ByVal sender As ObjectByVal e As DockPositionChangedEventArgs) 
            Dim dock As RadDock = DirectCast(sender, RadDock) 
            If e.DockZoneID = [String].Empty Then 
                dock.Text = [String].Format("I used to be in {0} but now I am floating.", _ 
                                            dock.DockZoneID) 
            Else 
                If dock.DockZoneID = [String].Empty Then 
                    dock.Text = "I used to be floating, but now I am docked in " + _ 
                                 e.DockZoneID 
                ElseIf dock.DockZoneID <> e.DockZoneID Then 
                    dock.Text = [String].Format("I moved from {0} to {1}.", _ 
                                                dock.DockZoneID, e.DockZoneID) 
                Else 
                    dock.Text = [String].Format("I moved from position {0} to position {1}.", _ 
                                                 dock.Index.ToString(), e.Index.ToString()) 
                End If 
            End If 
            If Not Me.Session("liste_felder"Is Nothing Then 
                Dim tobjListeFelder As ArrayList 
 
                tobjListeFelder = Me.Session("liste_felder"
 
            End If 
        End Sub 
 
        ''' <summary> 
        ''' Seite initialisieren 
        ''' </summary> 
        Protected Sub Page_Init(ByVal sender As ObjectByVal e As System.EventArgs) Handles MyBase.Init 
            Me._id_produkt = Me.globalContext.QueryString("id_produkt"
            btnZurueck.url = Me.globalContext.URLContext.ermittleURL_AlleParameterAdmin(Me.globalContext.URLContext.id_seite, Me.globalContext.URLContext.id_seite, Me.globalContext.URLContext.id_vonmodul, -1, Me._id_produkt, -1, , , , , , , True"id_produkt="
 
            If Not Me.IsPostBack() Then 
                Dim tAnzahl As Integer 
                Dim tobjKonditionendefinitionenListe As New class_banken_produktdb_konditionendefinitionen_liste() 
 
                ' Anzahl der schon definierten Felder ermitteln 
                tAnzahl = tobjKonditionendefinitionenListe.ermittleAnzahlBeiProduktvonTab_banken_konditionendefinitionen(Me._id_produkt) 
 
                ' Anzahl und Felder initialisieren 
                If tAnzahl = 0 Then 
                    Me.Session.Add("anzahl_felder", 0) 
                    Me.Session.Add("liste_felder"New ArrayList()) 
                Else 
                    Me.Session.Add("anzahl_felder", tAnzahl) 
                    Me.Session.Add("liste_felder"Me.setzeListeFelder()) 
                End If 
 
                ' Erzeugt die Controls 
                Me.erzeugeInhalte() 
            Else 
                ''Recreate the docks in order to ensure their proper operation 
                Dim i As Integer = 0 
                While i < CurrentDockStates.Count 
                    Dim dock As RadDock = CreateRadDockFromState(CurrentDockStates(i)) 
                    'We will just add the RadDock control to the RadDockLayout. 
                    ' You could use any other control for that purpose, just ensure 
                    ' that it is inside the RadDockLayout control. 
                    ' The RadDockLayout control will automatically move the RadDock 
                    ' controls to their corresponding zone in the LoadDockLayout 
                    ' event (see below). 
                    RadDockLayout1.Controls.Add(dock) 
                    'We want to save the dock state every time a dock is moved. 
                    CreateSaveStateTrigger(dock) 
                    System.Math.Max(System.Threading.Interlocked.Increment(i), i - 1) 
                End While 
            End If 
        End Sub 
 
        ''' <summary> 
        ''' Setzt die Liste mit den vorhanden Controls 
        ''' </summary> 
        Private Function setzeListeFelder() As ArrayList 
            Dim tobjListe As New ArrayList 
            Dim tobjKonditonendefinitionen As class_banken_produktdb_konditionendefinitionen 
            Dim tobjKonditionendefinitionenListe As New class_banken_produktdb_konditionendefinitionen_liste() 
 
            ' Alle vorhanden Definitionen ermitteln und die IDs als Liste zurückliefern, somit kann später ein 
            ' Abgleich gemacht werden ob die Definition schon in der DB ist oder nicht, d.h. neu geschrieben werden 
            ' muss oder nicht 
            tobjKonditionendefinitionenListe.ermittleListeBeiProduktvonTab_banken_konditionendefinitionen(Me._id_produkt) 
            For Each tobjKonditonendefinitionen In tobjKonditionendefinitionenListe 
                tobjListe.Add(tobjKonditonendefinitionen.getValue("id")) 
            Next 
 
            Return tobjListe 
        End Function 
 
        ''' <summary> 
        ''' Erzeugt den Inhalt für die dynamisch angelegten Felder 
        ''' </summary> 
        Private Sub erzeugeInhalte() 
            ' Erzeuge die Inhalte für die liste_felder 
            If Not Me.Session("liste_felder"Is Nothing Then 
                For Each tid_definition As Integer In Me.Session("liste_felder"
                    Dim tobjRadDock As New RadDock() 
 
                    tobjRadDock.ID = "radDock" & tid_definition 
                    tobjRadDock.DockMode = DockMode.Docked 
                    tobjRadDock.UniqueName = tid_definition 
                    tobjRadDock.Title = tid_definition 
                    tobjRadDock.Text = tid_definition 
                    'tobjRadDock.AutoPostBack = True 
                    'AddHandler tobjRadDock.DockPositionChanged, AddressOf RadDock1_DockPositionChanged 
                    tobjRadDock.Controls.Add(Me.erzeugeNeuenTabellenEintragFeld(tid_definition)) 
                    Me.RadDockZoneFelder.Controls.Add(tobjRadDock) 
                    CreateSaveStateTrigger(tobjRadDock) 
 
 
                    'Me.paInhaltKonditionDefinitionen.Controls.Add(Me.erzeugeNeuenTabellenEintragFeld(tid_definitiion)) 
                Next 
            End If 
        End Sub 
 



2 Answers, 1 is accepted

Sort by
0
Frank Kocher
Top achievements
Rank 1
answered on 08 Feb 2010, 12:32 PM
Hi,

while debugging i found out that the LoadDockLayout event wil not be fired. The RadDockLayout1_SaveDockLayout event will be fired normal.

I hope someone has any hint for me.

Frank
0
Pero
Telerik team
answered on 09 Feb 2010, 08:46 AM
Hello Frank,

I examined your code and it seems that everything is OK. The docks are recreated on every postback, you are handling the LoadDockLayout event to place the docks at their correct position and zone, and you are saving the state in the Session. To overcome the issue try the following and in case the problem persists please open a new support ticket and send us a fully working project that recreates the error.
  • If the DockLayout is placed within a UserControl, which on the other hand is added dynamically in the Page_Load event, the LoadDockLayout event will not be triggered because it is fired immediately after the Page_Init event. The following help article describes the RadDock lifecycle: http://www.telerik.com/help/aspnet-ajax/dock_dockcontrollifecycle.html. Please make sure that the user control is loaded before LoadDockLayout is fired i.e. in the Page_Init event.
  • Enable the ViewState on the RadDockLayout control


Kind regards,
Pero
the Telerik team

Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Follow the status of features or bugs in PITS and vote for them to affect their priority.
Tags
Dock
Asked by
Frank Kocher
Top achievements
Rank 1
Answers by
Frank Kocher
Top achievements
Rank 1
Pero
Telerik team
Share this question
or