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

Saving state in Database

2 Answers 77 Views
Dock
This is a migrated thread and some comments may be shown as answers.
Sam
Top achievements
Rank 1
Sam asked on 05 May 2009, 06:33 PM
I am really close to getting this to work but I'm missing something. I have it saving the state in our Database but it's not saving the correct order it's just submitting the original layout, not the latest. I'm guesing I am either missing something or have it in the wrong places. Here is the entire code behind.

<CODE>

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()

 

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

 

RadDockZone1.Controls.Add(soRadDock)

CreateSaveStateTriggers(soRadDock)

 

End If

 

 

If drContacts("Zone") = 0 Then

 

RadDockZone0.Controls.Add(soRadDock)

CreateSaveStateTriggers(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.GetSession("ContactNumber").ToString())

 

 

If PortalDataAccess.LoadState(ContactID) IsNot Nothing Then

 

_state = PortalDataAccess.LoadState(ContactID).ToString()

 

End If

 

 

If _state Is Nothing Then

 

CurrentDockStates = _currentDockStates

 

Else

 

 

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

 

 

End If

 

 

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)

 

 

For Each state As DockState In CurrentDockStates

 

e.Positions(state.UniqueName) = state.DockZoneID

e.Indices(state.UniqueName) = state.Index

 

Next

 

 

 

 

End Sub

 

 

Private Sub CreateSaveStateTriggers(ByVal dock As RadDock)

 

 

'Ensure that the RadDock control will initiate postback

 

 

' when its position changes on the client. 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

 

 

 

 

 

 

Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click

 

Response.Cookies(

"DockLayout").Value = ""

 

Response.Redirect(

"default.aspx")

 

 

End Sub

 

 

 

 

Protected Sub ButtonAddDock_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ButtonAddDock.Click

 

 

End Sub

 

End

 

Class

 



</CODE>

2 Answers, 1 is accepted

Sort by
0
Sam
Top achievements
Rank 1
answered on 06 May 2009, 01:18 PM
Nevermind on this issue I got it to work. I can't however get it to save the close and collapsed state, anyone know how to do this?


Thanks,
Sam
0
Obi-Wan Kenobi
Top achievements
Rank 1
answered on 07 May 2009, 09:57 AM
You should set dock.CommandsAutoPostBack = true;
so once you press a command it will make an additional postback/ajax call and the new state will be saved into the DB.
A simple example is available here(state is saved in session):
http://demos.telerik.com/aspnet-ajax/dock/examples/myportal/defaultcs.aspx
Tags
Dock
Asked by
Sam
Top achievements
Rank 1
Answers by
Sam
Top achievements
Rank 1
Obi-Wan Kenobi
Top achievements
Rank 1
Share this question
or