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

radDock Close and Minimize Problem when save

15 Answers 182 Views
Dock
This is a migrated thread and some comments may be shown as answers.
Mohammad
Top achievements
Rank 1
Mohammad asked on 21 Mar 2009, 06:03 AM
Dear All,

when save the docks on page after user cusomize position and every thing on cookies using this code,,,


protected

void RadDockLayout1_LoadDockLayout(object sender, Telerik.Web.UI.DockLayoutEventArgs e)

 

{

HttpCookie dockState = Page.Request.Cookies.Get(

"MyApplicationDockStates85216");

 

 

if (dockState != null)

 

{

 

string serializedList = dockState.Value;

 

 

if (serializedList != null)

 

{

 

string[] states = serializedList.Split('|');

 

 

for (int i = 0; i < states.Length; i++)

 

{

DockState state = DockState.Deserialize(states[i]);

e.Positions[state.UniqueName] = state.DockZoneID;

e.Indices[state.UniqueName] = state.Index;

}

}

}
}

and 

 

protected

void RadDockLayout1_SaveDockLayout(object sender, Telerik.Web.UI.DockLayoutEventArgs e)

 

{

HttpCookie dockState = Page.Response.Cookies.Get(

"MyApplicationDockStates85216");

 

 

if (dockState == null)

 

{

dockState =

new HttpCookie("MyApplicationDockStates85216");

 

Page.Response.Cookies.Add(dockState);

}

 

List<DockState> stateList = ((RadDockLayout)sender).GetRegisteredDocksState();

 

 

StringBuilder serializedList = new StringBuilder();

 

 

for (int i = 0; i < stateList.Count; i++)

 

{

serializedList.Append(stateList[i].ToString());

serializedList.Append(

"|");

 

}

dockState.Expires =

DateTime.Today.AddMonths(1);

 

dockState.Value = serializedList.ToString();

 

}

all position saved and every thing well but closed Docks or minimze Docks not saved
i.e when close dock or minmize dock,,,,after postback the closed/minimzed docks still as first time

anyone have solution for this problem?

thanks in advanced

15 Answers, 1 is accepted

Sort by
0
Mohammad
Top achievements
Rank 1
answered on 22 Mar 2009, 06:02 AM
no any answer!!!!!!!!!!!!!!!!!!!!
0
Petio Petkov
Telerik team
answered on 23 Mar 2009, 06:02 PM
Hello Mohammad,

Try to invoke  dock.ApplyState(state); in RadDockLayout1_LoadDockLayout handler, e.g.

void RadDockLayout1_LoadDockLayout(object sender, Telerik.Web.UI.DockLayoutEventArgs e)
{
............
{

DockState state = DockState.Deserialize(states[i]);
RadDock dock = (RadDock)RadDockLayout1.FindControl(state.UniqueName);
dock.ApplyState(state);
e.Positions[state.UniqueName] = state.DockZoneID;
e.Indices[state.UniqueName] = state.Index;
}
......
}

Hope this helps.

All the best,

Petio Petkov
the Telerik team


Check out Telerik Trainer , the state of the art learning tool for Telerik products.
0
Sam
Top achievements
Rank 1
answered on 24 Apr 2009, 04:08 PM
I get an error on this "states[i]" What is states?

Thanks,
Sam
0
Sam
Top achievements
Rank 1
answered on 27 Apr 2009, 01:20 PM
Any answer on this problem? states[i] isn't defined in your block of code.
0
Sam
Top achievements
Rank 1
answered on 28 Apr 2009, 01:39 PM
Petio,

Can you explain what states[i] is????? I get a compile error because it's not defined.

void RadDockLayout1_LoadDockLayout(object sender, Telerik.Web.UI.DockLayoutEventArgs e)
{
............
{
DockState state = DockState.Deserialize(states[i]);
RadDock dock = (RadDock)RadDockLayout1.FindControl(state.UniqueName);
dock.ApplyState(state);
e.Positions[state.UniqueName] = state.DockZoneID;
e.Indices[state.UniqueName] = state.Index;
}
......
}
0
Obi-Wan Kenobi
Top achievements
Rank 1
answered on 28 Apr 2009, 02:35 PM
List<DockState> states = RadDockLayout1.GetRegisteredDocksState() will return all registered RadDock states.
You could get a particular state with this code:   DockState state = RadDockLayout1.GetRegisteredDocksState()[0];
states[i]  is a single RadDock's state

0
Sam
Top achievements
Rank 1
answered on 28 Apr 2009, 03:48 PM
Thanks for the reply Obi Wan,

I still get a compile error, this time is doesn't know what "i" is, when i dim it to an integer I get a new error. here is my block of code.

 

Dim states As List(Of DockState) = RadDockLayout1.GetRegisteredDocksState()

 

 

Dim state As DockState = DockState.Deserialize(states(i))

 

 

Dim dock As RadDock = DirectCast(RadDockLayout1.FindControl(state.UniqueName), RadDock)

 

dock.ApplyState(state)

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

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


here is the error when i dim it to an int.

"Error 19 Value of type 'Telerik.Web.UI.DockState' cannot be converted to 'String'."



Thanks For your help.

0
Sam
Top achievements
Rank 1
answered on 29 Apr 2009, 02:56 PM
Anyone have an answer on this?
0
Obi-Wan Kenobi
Top achievements
Rank 1
answered on 01 May 2009, 12:25 PM

Dim states As List(Of DockState) = RadDockLayout1.GetRegisteredDocksState()

- states is List of DockStates

 So this is wrong:

 

Dim state As DockState = DockState.Deserialize(states(i))
because:
states(i) type is DockState  but DockState.Deserialize(STRING);


If you want to serialize a DockState, you should use:  Dim stateString As String  = stateList[i].ToString()
otherwise you should use:                                         DockState.Deserialize(stateString);

0
Sam
Top achievements
Rank 1
answered on 01 May 2009, 02:29 PM
Thanks for the reply, can you post the entire block of code? Here is my code based on what I have gotten out of this forum but it won't compile.

 

 

 

 

Dim states As List(Of DockState) = RadDockLayout1.GetRegisteredDocksState()

 

 

 

Dim state As DockState = DockState.Deserialize(states(i))

 

 

 

Dim dock As RadDock = DirectCast(RadDockLayout1.FindControl(state.UniqueName), RadDock)

 

dock.ApplyState(state)

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

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

 

 

 

 

0
Sam
Top achievements
Rank 1
answered on 01 May 2009, 02:47 PM
I've got it down to this but I'm right back where I was last week........ "i" is not defined. Can someone please look at this block of code and tell me how to fix it?????

Dim

 

stateList As List(Of DockState) = DirectCast(sender, RadDockLayout).GetRegisteredDocksState()

 

 

Dim stateString As String = stateList(i).ToString()

 

 

Dim state As DockState = DockState.Deserialize(stateString)

 

 

Dim dock As RadDock = DirectCast(RadDockLayout1.FindControl(state.UniqueName), RadDock)

 

dock.ApplyState(state)

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

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

0
Obi-Wan Kenobi
Top achievements
Rank 1
answered on 01 May 2009, 03:15 PM

"i" is not defined - because "i" is not defined.

The code should be:

 Dim stateList As List(Of DockState) = RadDockLayout1.GetRegisteredDocksState()  
        Dim i As Integer = 0  
        While i < stateList.Count  
            Dim stateString As String = stateList(i).ToString()  
            i = i + 1  
        End While 

Or you could use For Each:

Dim stateList As List(Of DockState) = RadDockLayout1.GetRegisteredDocksState()  
        For Each state As DockState In stateList  
            Dim stateString As String = state.ToString()  
        Next 

You could read about the List class here:
http://msdn.microsoft.com/en-us/library/6sh2ey19.aspx
0
Sam
Top achievements
Rank 1
answered on 01 May 2009, 03:34 PM
I got the entire code blaock to compile, I'll post it for anyone wanting the complete solution, how ever it isn't saving the collapsed or closed state....... I am pulling the controls dynamically from a database and populating the rad dock with user controls, any one know why this might be happening? Im not saving the state in the database, im using the cookie based state.

Thanks,
Sam

Code

 

Dim stateList As List(Of DockState) = RadDockLayout1.GetRegisteredDocksState()

 

 

Dim stateString As String

 

 

Dim i As Integer = 0

 

 

While i < stateList.Count

 

stateString = stateList(i).ToString()

i = i + 1

 

End While

 

 

Dim state As DockState = DockState.Deserialize(stateString)

 

 

Dim dock As RadDock = DirectCast(RadDockLayout1.FindControl(state.UniqueName), RadDock)

 

dock.ApplyState(state)

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

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




/Code
0
Obi-Wan Kenobi
Top achievements
Rank 1
answered on 05 May 2009, 08:19 AM
If you collapse or close a RadDock you should make an additional ajax call/postback to save its state.
You could find a simple example which illustrates how to save the state on each move/collapse/expand/close here:
http://demos.telerik.com/aspnet-ajax/dock/examples/myportal/defaultcs.aspx
0
Maas Prog
Top achievements
Rank 1
answered on 04 Mar 2010, 05:58 PM
HI All - I was having same question and documentation is confusing at best for some of us... Here is what finally worked for me:
  Protected Sub RadDockLayout1_LoadDockLayout(ByVal sender As Object, ByVal e As Telerik.Web.UI.DockLayoutEventArgs)

        Dim serializer As New Script.Serialization.JavaScriptSerializer()
        'Get saved state string from the database - set it to dockState variable for example  
        Dim dockstate As String = ""
        Using db As New promptUser
            dockstate = db.GetProjectDockState(nProjectID)
        End Using
        If dockstate <> "" Then
            Dim currentDockStates As String() = dockstate.Split("|")
            For Each stringState As String In currentDockStates
                If stringState <> String.Empty Then
                    Dim state As DockState = serializer.Deserialize(Of DockState)(stringState)

                    Dim dock As RadDock = RadDockLayout1.FindControl(state.UniqueName)
                    dock.ApplyState(state)
                    
                    e.Positions(state.UniqueName) = state.DockZoneID
                    e.Indices(state.UniqueName) = state.Index

                End If
            Next
        End If
        
 
      'Reset the non changeable dock properties
        dockProjectOverview.Height = Unit.Pixel(400)
        CreateSaveStateTrigger(dockProjectOverview)
        
        dockBudgetOverview.Height = Unit.Pixel(375)
        CreateSaveStateTrigger(dockBudgetOverview)
        
        dockNotes.Height = Unit.Pixel(250)
        CreateSaveStateTrigger(dockNotes)
        
        dockTeamMembers.Height = Unit.Pixel(250)
        CreateSaveStateTrigger(dockTeamMembers)

    End Sub
    
    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


And in the ASPX page i put this right at the end of the layout tags:
             <div style="width: 0px; height: 0px; overflow: hidden; position: absolute; left: -10000px;">
                Hidden UpdatePanel, which is used to help with saving state when minimizing, moving
                and closing docks. This way the docks state is saved faster (no need to update the
                docking zones).
                <asp:UpdatePanel runat="server" ID="UpdatePanel1">
                </asp:UpdatePanel>
                </div>


Hope this helps -- ford

Tags
Dock
Asked by
Mohammad
Top achievements
Rank 1
Answers by
Mohammad
Top achievements
Rank 1
Petio Petkov
Telerik team
Sam
Top achievements
Rank 1
Obi-Wan Kenobi
Top achievements
Rank 1
Maas Prog
Top achievements
Rank 1
Share this question
or