Hi,
I couldn't run the code as is. That's why I made some modifications, and managed to run it. However, I didn't experience any problems with positioning of the docks.Here is the code for you to test. Please, modify it accordingly, so the problem is reproduced, and send it back.
Please note that, the
LoadDockLayout event is fired immediately after the Page.InitComplete, and if the user control is loaded dynamically, it should be added in the Page.Init or
LoadDockLayout will not be fired.
.aspx
.cs
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Web;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
Telerik.Web.UI;
public
partial
class
CreateDocksDynamically : System.Web.UI.Page
{
private
List<DockState> CurrentDockStates
{
get
{
// Store the info about the added docks in the session.
List<DockState> _currentDockStates = (List<DockState>)Session[
"CurrentDockStatesDynamicDocks"
];
if
(Object.Equals(_currentDockStates,
null
))
{
_currentDockStates =
new
List<DockState>();
Session[
"CurrentDockStatesDynamicDocks"
] = _currentDockStates;
}
return
_currentDockStates;
}
set
{
Session[
"CurrentDockStatesDynamicDocks"
] = value;
}
}
const
string
TitleBarText =
"TitleText"
;
const
string
CurrentRank =
"CurRankText"
;
const
string
PreviousRank =
"PreRankText"
;
protected
void
Page_Load(
object
sender, EventArgs e)
{
}
protected
override
void
OnInit(EventArgs e)
{
base
.OnInit(e);
if
(!Page.IsPostBack)
{
for
(
int
i = 0; i < 5; i++)
{
RadDock dock = CreateRadDock(i);
if
(i % 2 == 0)
{
RadDockZone1.Controls.Add(dock);
}
else
{
RadDockZone2.Controls.Add(dock);
}
}
}
else
{
for
(
int
i = 0; i < CurrentDockStates.Count; i++)
{
RadDock dock = CreateRadDockFromState(CurrentDockStates[i]);
RadDockLayout1.Controls.Add(dock);
CreateSaveStateTrigger(dock);
}
}
}
private
RadDock CreateRadDockFromState(DockState state)
{
RadDock dock =
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());
dock.AutoPostBack =
true
;
dock.CommandsAutoPostBack =
true
;
return
dock;
}
private
RadDock CreateRadDock(
int
i)
{
RadDock dock =
new
RadDock();
dock.DockMode = DockMode.Docked;
dock.UniqueName = Guid.NewGuid().ToString();
dock.ID =
string
.Format(
"RadDock{0}"
, dock.UniqueName);
dock.Title =
"Dock"
+ i.ToString();
dock.Text =
string
.Format(
"Added at {0}"
, DateTime.Now);
dock.Width = Unit.Pixel(300);
dock.AutoPostBack =
true
;
dock.CommandsAutoPostBack =
true
;
dock.Commands.Add(
new
DockCloseCommand());
dock.Commands.Add(
new
DockExpandCollapseCommand());
return
dock;
}
private
void
CreateSaveStateTrigger(RadDock dock)
{
// 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
;
}
protected
void
RadDockLayout1_LoadDockLayout(
object
sender, DockLayoutEventArgs e)
{
foreach
(DockState state
in
CurrentDockStates)
{
e.Positions[state.UniqueName] = state.DockZoneID;
e.Indices[state.UniqueName] = state.Index;
}
}
protected
void
RadDockLayout1_SaveDockLayout(
object
sender, DockLayoutEventArgs e)
{
CurrentDockStates =
new
List<DockState>();
foreach
(DockState ds
in
RadDockLayout1.GetRegisteredDocksState())
{
CurrentDockStates.Add(ds);
}
}
}
Kind regards,
Pero
the Telerik team
Do you want to have your say when we set our development plans?
Do you want to know when a feature you care about is added or when a bug fixed?
Explore the
Telerik Public Issue Tracking
system and vote to affect the priority of the items.