Hi,
I am trying to figure out why I am having a problem with RadDock when I use a master page. If I split the same functionality up using a master page then I seem to have problems when I dynamically create a RadDock. I think it might have something to do with the fact that the first time a RadDock is created it is in a postback click handler, subsequent creation of the RadDock happen in the init handler. However, I only see this problem when I use a master page. I do not see the same problem when all code is within a single page.
The problem I am having is that I create a RadDock in a click handler and then I attempt to move the RadDock to a different zone, the RadDock 'snaps' back to the zone it was created in, if I then try to move the RadDock I am successful.
I have included a DockNoMaster.aspx/cs which works as I expect. I can click on Add Module and a RadDock is created in the middle zone. I can move the RadDock to the right or left zone and click Postback and the RadDock 'remebers' its position.
--DockNoMaster.aspx
<telerik:RadScriptManager ID="ScriptManager1" runat="server" />
<telerik:RadDockLayout runat="server" ID="RadDockLayout1" EnableEmbeddedSkins="false" >
<table>
<tr>
<td bgcolor="#99ffcc">
<telerik:RadDockZone runat="server" ID="leftZone" Width="200" MinHeight="200" Orientation="vertical" Style="border: 0px;" />
</td>
<td bgcolor="#99ffcc">
<asp:Button runat="server" ID="btnAddModule" OnClick="btnAddModule_Click" Text="Add Module" />
<asp:Button runat="server" ID="btnPostback" OnClick="btnPostback_Click" Text="Postback" />
<br /><br />
<telerik:RadDockZone runat="server" ID="middleZone" Width="200" MinHeight="200" Orientation="vertical" Style="border: 0px;" />
</td>
<td bgcolor="#99ffcc">
<telerik:RadDockZone runat="server" ID="rightZone" Width="200" MinHeight="200" Orientation="vertical" Style="border: 0px;" />
</td>
</tr>
</table>
</telerik:RadDockLayout>
--DockNoMaster.cs
public
partial class Test_Templates_DockNoMaster : System.Web.UI.Page
{
protected void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)
{
}
}
private List<DockState> CurrentDockStates
{
get
{
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;
}
}
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;
}
void dock_DockPositionChanged(object sender, DockPositionChangedEventArgs e)
{
}
private RadDock CreateRadDock()
{
int docksCount = CurrentDockStates.Count;
RadDock dock = new RadDock();
dock.DockMode =
DockMode.Docked;
dock.UniqueName =
Guid.NewGuid().ToString();
dock.ID =
string.Format("RadDock{0}", dock.UniqueName);
dock.Title =
"Dock";
dock.Text =
string.Format("Added at {0}", DateTime.Now);
dock.Width =
Unit.Pixel(300);
dock.Commands.Add(
new DockCloseCommand());
dock.Commands.Add(
new DockExpandCollapseCommand());
dock.AutoPostBack =
true;
dock.CommandsAutoPostBack =
true;
return dock;
}
protected void Page_Init(object sender, EventArgs e)
{
RadDockLayout dockLayout = RadDockLayout1;
dockLayout.LoadDockLayout +=
new DockLayoutEventHandler(dockLayout_LoadDockLayout);
dockLayout.SaveDockLayout +=
new DockLayoutEventHandler(dockLayout_SaveDockLayout);
for (int i = 0; i < CurrentDockStates.Count; i++)
{
RadDock dock = CreateRadDockFromState(CurrentDockStates[i]);
dockLayout.Controls.Add(dock);
}
}
protected void dockLayout_LoadDockLayout(object sender, DockLayoutEventArgs e)
{
foreach (DockState state in CurrentDockStates)
{
e.Positions[state.UniqueName] = state.DockZoneID;
e.Indices[state.UniqueName] = state.Index;
}
}
protected void dockLayout_SaveDockLayout(object sender, DockLayoutEventArgs e)
{
RadDockLayout dockLayout = RadDockLayout1;
CurrentDockStates = dockLayout.GetRegisteredDocksState();
}
protected void btnAddModule_Click(object sender, EventArgs e)
{
RadDockLayout dockLayout = RadDockLayout1;
RadDock dock = CreateRadDock();
middleZone.Controls.Add(dock);
}
protected void btnPostback_Click(object sender, EventArgs e)
{
}
}
I have also included DockWithMaster.aspx/cs and DockMaster.master/cs which does not work as I expect. If I click Add Module then a RadDock is created in the middle zone. However, if I drag the RadDock to the left or right zone it immediately goes back to the middle zone. The second time I move the RadDock to the left or right zone, it will remember its position.
In the master sample the RadDockLayout and the left and right RadDockZone are in the DockMaster.master file. The middle RadDockZone and the add and postback buttons are in the DockWithMaster.aspx file. The saving and loading of dock state is handled in the content .aspx file, not the master.
-- DockMaster.master
<telerik:RadScriptManager ID="ScriptManager1" runat="server" />
<telerik:RadDockLayout runat="server" ID="RadDockLayout1" EnableEmbeddedSkins="false" >
<table>
<tr>
<td bgcolor="#99ffcc">
<telerik:RadDockZone runat="server" ID="leftZone" Width="200" MinHeight="200" Orientation="vertical" Style="border: 0px;" />
</td>
<td bgcolor="#99ffcc">
<asp:ContentPlaceHolder id="middleContent" runat="server" />
</td>
<td bgcolor="#99ffcc">
<telerik:RadDockZone runat="server" ID="rightZone" Width="200" MinHeight="200" Orientation="vertical" Style="border: 0px;" />
</td>
</tr>
</table>
</telerik:RadDockLayout>
-- DockMaster.cs does not have anything in it
-- DockWithMaster.aspx
<
asp:Content ID="Content1" ContentPlaceHolderID="middleContent" runat="server">
<asp:Button runat="server" ID="btnAddModule" OnClick="btnAddModule_Click" Text="Add Module" />
<asp:Button runat="server" ID="btnPostback" OnClick="btnPostback_Click" Text="Postback" />
<br /><br />
<telerik:RadDockZone runat="server" ID="middleZone" Width="200" MinHeight="200" Orientation="vertical" Style="border: 0px;" />
</
asp:Content>
-- DockWithMaster.cs
public
partial class Test_Templates_DockWithMaster : System.Web.UI.Page
{
protected void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)
{
}
}
private List<DockState> CurrentDockStates
{
get
{
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;
}
}
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;
}
void dock_DockPositionChanged(object sender, DockPositionChangedEventArgs e)
{
}
private RadDock CreateRadDock()
{
int docksCount = CurrentDockStates.Count;
RadDock dock = new RadDock();
dock.DockMode =
DockMode.Docked;
dock.UniqueName =
Guid.NewGuid().ToString();
dock.ID =
string.Format("RadDock{0}", dock.UniqueName);
dock.Title =
"Dock";
dock.Text =
string.Format("Added at {0}", DateTime.Now);
dock.Width =
Unit.Pixel(300);
dock.Commands.Add(
new DockCloseCommand());
dock.Commands.Add(
new DockExpandCollapseCommand());
dock.AutoPostBack =
true;
dock.CommandsAutoPostBack =
true;
return dock;
}
protected void Page_Init(object sender, EventArgs e)
{
RadDockLayout dockLayout = (RadDockLayout)this.Master.FindControl(middleZone.LayoutID);
dockLayout.LoadDockLayout +=
new DockLayoutEventHandler(dockLayout_LoadDockLayout);
dockLayout.SaveDockLayout +=
new DockLayoutEventHandler(dockLayout_SaveDockLayout);
for (int i = 0; i < CurrentDockStates.Count; i++)
{
RadDock dock = CreateRadDockFromState(CurrentDockStates[i]);
dockLayout.Controls.Add(dock);
}
}
protected void dockLayout_LoadDockLayout(object sender, DockLayoutEventArgs e)
{
foreach (DockState state in CurrentDockStates)
{
e.Positions[state.UniqueName] = state.DockZoneID;
e.Indices[state.UniqueName] = state.Index;
}
}
protected void dockLayout_SaveDockLayout(object sender, DockLayoutEventArgs e)
{
RadDockLayout dockLayout = (RadDockLayout)this.Master.FindControl(middleZone.LayoutID);
CurrentDockStates = dockLayout.GetRegisteredDocksState();
}
protected void btnAddModule_Click(object sender, EventArgs e)
{
RadDockLayout dockLayout = (RadDockLayout)this.Master.FindControl(middleZone.LayoutID);
RadDock dock = CreateRadDock();
middleZone.Controls.Add(dock);
}
protected void btnPostback_Click(object sender, EventArgs e)
{
}
}