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
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,
the Telerik team
Check out Telerik Trainer , the state of the art learning tool for Telerik products.
Thanks,
Sam
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;
}
......
}
You could get a particular state with this code: DockState state = RadDockLayout1.GetRegisteredDocksState()[0];
states[i] is a single RadDock's state
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.
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);
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
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
"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
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
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