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

Loading Dockstates from DB

3 Answers 55 Views
Dock
This is a migrated thread and some comments may be shown as answers.
Geoff
Top achievements
Rank 1
Geoff asked on 31 Jul 2010, 02:05 PM

Hi there

I have been experimenting with loading and saving dock states to a DB but have an issue.

When I run the code the docks are not added to the page - rather they are but the source code has a 'style display:none' so I presume this is hiding the docks?? Its all I can think off as I cant see any other issues.

Can somebody have a look below and see what I am doing wrong........

This is the ASPX.................

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Test Docks.aspx.vb" Inherits="IFM_Code_Testing.Test_Docks" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
  
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  
<head runat="server">
    <title></title>
    <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
  
        <script type="text/javascript">
            var currentLoadingPanel = null;
            var currentUpdatedControl = null;
            function RequestStart(sender, args) {
                currentLoadingPanel = $find("LoadingPanel1");
                currentUpdatedControl = "TableLayout";
                currentLoadingPanel.show(currentUpdatedControl);
            }
            function ResponseEnd() {
                //hide the loading panel and clean up the global variables
                if (currentLoadingPanel != null)
                    currentLoadingPanel.hide(currentUpdatedControl);
                currentUpdatedControl = null;
                currentLoadingPanel = null;
            }            
        </script>
  
    </telerik:RadCodeBlock>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
      
    <div >
        <asp:Panel ID="Panel1" runat="server">
            <telerik:RadDockLayout ID="RDLayout" Runat="server" OnSaveDockLayout="RDLayout_SaveDockLayout" OnLoadDockLayout="RDLayout_LoadDockLayout" EnableEmbeddedSkins="false">
                <table id="TableLayout">
                    <tr>
                        <td>
                            <telerik:RadDockZone ID="RDZoneLeft" runat="server" Width="300" MinHeight="300" ></telerik:RadDockZone>
                        </td>
                        <td>
                            <telerik:RadDockZone ID="RDZoneRight" runat="server" Width="300" MinHeight="300"  ></telerik:RadDockZone>
                        </td>
                    </tr>
                </table>
            </telerik:RadDockLayout>
        </asp:Panel>
   </div>
    <telerik:RadAjaxManager ID="RAManager" runat="server" ClientEvents-OnRequestStart="RequestStart" ClientEvents-OnResponseEnd="ResponseEnd"></telerik:RadAjaxManager>
    <telerik:RadAjaxLoadingPanel ID="LoadingPanel1" runat="server" MinDisplayTime="500" Skin="Default"></telerik:RadAjaxLoadingPanel>
    </form>
</body>
</html>


And this is the ASPX.VB...
Imports System
Imports System.Collections.Generic
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports Telerik.Web.UI
Imports System.Text
Imports System.Data.SqlClient
Imports System.Collections
Imports System.Configuration
  
Public Class Test_Docks
    Inherits System.Web.UI.Page
    Private _conn As New SqlConnection(ConfigurationManager.ConnectionStrings("dbconnectionsstring").ConnectionString)
    Private _userID As Integer = 999999
    Private ReadOnly Property CurrentDockStates() As List(Of DockState)
        Get
            'Get saved state string from the database - set it to dockState variable for example 
            Dim dockStatesFromDB As String = ""
  
            _conn.Open()
            Dim command As New SqlCommand("select state from IFM_User_Page_Layout where UserID=999999", _conn)
            dockStatesFromDB = command.ExecuteScalar().ToString()
            _conn.Close()
  
            Dim _currentDockStates As New List(Of DockState)()
            Dim stringStates As String() = dockStatesFromDB.Split("|"c)
            For Each stringState As String In stringStates
                If stringState.Trim() <> String.Empty Then
                    _currentDockStates.Add(DockState.Deserialize(stringState))
                End If
            Next
            Return _currentDockStates
        End Get
    End Property
  
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  
    End Sub
  
    Protected Sub Page_Init(ByVal sender As Object, ByVal e As EventArgs)
        'Recreate the docks in order to ensure their proper operation
        Dim i As Integer = 0
        While i < CurrentDockStates.Count
            If CurrentDockStates(i).Closed = False Then
                Dim dock As RadDock = CreateRadDockFromState(CurrentDockStates(i))
                 CreateSaveStateTrigger(dock)
                   ' LoadWidget(dock)
  
                RDLayout.Controls.Add(dock)
            End If
            System.Math.Max(System.Threading.Interlocked.Increment(i), i - 1)
        End While
    End Sub
  
    Protected Sub RDLayout_LoadDockLayout(ByVal sender As Object, ByVal e As DockLayoutEventArgs)
        For Each state As DockState In CurrentDockStates
            e.Positions(state.UniqueName) = state.DockZoneID
            e.Indices(state.UniqueName) = state.Index
        Next
    End Sub
  
    Protected Sub RDLayout_SaveDockLayout(ByVal sender As Object, ByVal e As DockLayoutEventArgs)
        Dim stateList As List(Of DockState) = RDLayout.GetRegisteredDocksState()
        Dim serializedList As New StringBuilder()
        Dim i As Integer = 0
  
        While i < stateList.Count
            serializedList.Append(stateList(i).ToString())
            serializedList.Append("|")
            System.Math.Max(System.Threading.Interlocked.Increment(i), i - 1)
        End While
  
        Dim dockState As String = serializedList.ToString()
        If dockState.Trim() <> [String].Empty Then
            _conn.Open()
            Dim command As New SqlCommand([String].Format("update States set State='{0}' where id='" + _userID.ToString() + "'", dockState), _conn)
            command.ExecuteNonQuery()
            _conn.Close()
        End If
    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.ApplyState(state)
  
        dock.Commands.Add(New DockCloseCommand())
        dock.Commands.Add(New DockExpandCollapseCommand())
  
        Return dock
    End Function
  
    Private Sub CreateSaveStateTrigger(ByVal dock As RadDock)
         dock.AutoPostBack = True
        dock.CommandsAutoPostBack = True
  
        Dim updatedControl As New AjaxUpdatedControl()
        updatedControl.ControlID = "Panel1"
  
        Dim setting1 As New AjaxSetting(dock.ID)
        setting1.EventName = "DockPositionChanged"
        setting1.UpdatedControls.Add(updatedControl)
  
        Dim setting2 As New AjaxSetting(dock.ID)
        setting2.EventName = "Command"
        setting2.UpdatedControls.Add(updatedControl)
  
        RAManager.AjaxSettings.Add(setting1)
        RAManager.AjaxSettings.Add(setting2)
    End Sub
  
End Class

And this is the state data from thr db (copied from an example on this site)...

{"UniqueName":"10bcf490-d081-4536-b542-df1564a8cade","DockZoneID":"RDZoneLeft","Width":"300px","Height":"","ExpandedHeight":"203","Top":"0px","Left":"0px","Resizable":"False","Closed":"False","Collapsed":"False","Pinned":"False","Title":"Dock","Text":"Added at 12/3/2009 3:40:54 PM","Tag":"~/Controls/ExchangeRates.ascx","Index":"0"}|{"UniqueName":"35ca0eed-774e-48f6-91ab-91dad4253153","DockZoneID":"RDZoneRight","Width":"300px","Height":"","ExpandedHeight":"138","Top":"0px","Left":"0px","Resizable":"False","Closed":"False","Collapsed":"False","Pinned":"False","Title":"Dock","Text":"Added at 12/3/2009 3:41:05 PM","Tag":"~/Controls/Horoscopes.ascx","Index":"0"}|

I cant seem to find any issues apart from the style one mentioned previously.

Any help greatly appreciated

3 Answers, 1 is accepted

Sort by
0
Geoff
Top achievements
Rank 1
answered on 31 Jul 2010, 02:09 PM
And this is the source code generated.....

<table id="TableLayout">
                    <tr>
                        <td>
                            <div id="RDZoneLeft" class="RadDockZone RadDockZone_Hay rdVertical" style="width:300px;min-width:10px;min-height:300px;">
        <!-- 2010.2.713.40 --><div class="RadDock RadDock_Default rdPlaceHolder" id="RDZoneLeft_D" style="display:none;">
            <!-- -->
        </div><input id="RDZoneLeft_ClientState" name="RDZoneLeft_ClientState" type="hidden" />
    </div>
                        </td>
                        <td>
                            <div id="RDZoneRight" class="RadDockZone RadDockZone_Hay rdVertical" style="width:300px;min-width:10px;min-height:300px;">
        <div class="RadDock RadDock_Default rdPlaceHolder" id="RDZoneRight_D" style="display:none;">
            <!-- -->
        </div><input id="RDZoneRight_ClientState" name="RDZoneRight_ClientState" type="hidden" />
    </div>
                        </td>
                    </tr>
                </table>
             
0
Geoff
Top achievements
Rank 1
answered on 31 Jul 2010, 05:12 PM
Ok I have managed to get this working - used an example and went from there.

I set up a simple page and can now load/save from DB.

But.......

When I try and intergrate the working code into a Master Page the docks do not get loaded..

I have a master page setup in which there are 3 ContentPlaceHolders. Then on a child page, based on the Master, I have added the code I have had working.

But when I load the page no docks????

Is there something else I need to do to get it to work with MasterPages?

The code is basically what I have alreayd showed previously.

Thanks in advance

Geoff
0
Geoff
Top achievements
Rank 1
answered on 01 Aug 2010, 09:21 AM
Hi there - please ignore this thread - all sorted now.

Made of couple of silly errors but got it sorted and everything working as it should.
 
Thanks
Tags
Dock
Asked by
Geoff
Top achievements
Rank 1
Answers by
Geoff
Top achievements
Rank 1
Share this question
or