Hello,
I am trying to use the example http://demos.telerik.com/aspnet-ajax/dock/examples/myportal/defaultcs.aspx on a masterpage. I have done some research and I think the error has to do with using the dock.ID instead of ClientID but not totally sure and am unsure of how to correct properly. Can anyone please give me a suggestion on how to correct he problem.
Thanks
I am trying to use the example http://demos.telerik.com/aspnet-ajax/dock/examples/myportal/defaultcs.aspx on a masterpage. I have done some research and I think the error has to do with using the dock.ID instead of ClientID but not totally sure and am unsure of how to correct properly. Can anyone please give me a suggestion on how to correct he problem.
Thanks
(inside pageview)...
<
asp:UpdatePanel
runat
=
"server"
ID
=
"UpdatePanel1"
ChildrenAsTriggers
=
"false"
UpdateMode
=
"Conditional"
>
<
ContentTemplate
>
<
telerik:RadDockLayout
runat
=
"server"
ID
=
"RadDockLayout1"
OnSaveDockLayout
=
"RadDockLayout1_SaveDockLayout"
OnLoadDockLayout
=
"RadDockLayout1_LoadDockLayout"
>
<
telerik:RadDockZone
runat
=
"server"
ID
=
"RadDockZone1"
Width
=
"550"
MinHeight
=
"50"
Style
=
"float: left"
UniqueName
=
"Folder Zone 1"
>
</
telerik:RadDockZone
>
<
telerik:RadDockZone
runat
=
"server"
ID
=
"RadDockZone2"
Width
=
"320"
MinHeight
=
"50"
Style
=
"float: left; background: #f5f4e8;"
UniqueName
=
"Folder Zone 2"
>
</
telerik:RadDockZone
>
<
telerik:RadDockZone
runat
=
"server"
ID
=
"RadDockZone3"
Width
=
"880"
MinHeight
=
"50"
Style
=
"background: #d5f0fa; float: left;"
UniqueName
=
"Folder Zone 3"
>
</
telerik:RadDockZone
>
<
div
style
=
"display: none"
>
Hidden UpdatePanel, which is used to receive the new dock controls. We will move
them with script to the desired initial dock zone.
<
asp:UpdatePanel
runat
=
"server"
ID
=
"UpdatePanel3"
>
<
Triggers
>
<
asp:AsyncPostBackTrigger
ControlID
=
"ButtonAddDock"
EventName
=
"Click"
/>
</
Triggers
>
</
asp:UpdatePanel
>
</
div
>
</
telerik:RadDockLayout
>
</
ContentTemplate
>
<
Triggers
>
<
asp:AsyncPostBackTrigger
ControlID
=
"ButtonAddDock"
EventName
=
"Click"
/>
</
Triggers
>
</
asp:UpdatePanel
>
-----------------------------------------------------------------------------------------------------------------------------------------
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;
using System.Web.Script.Serialization;
using System.Text;
using System.Collections;
public partial class MBA_Folder : System.Web.UI.Page
{
private const string cookiename = "__dockState";
private List<
DockState
> GetDocks(string cookieName)
{
List<
DockState
> currentDocks = new List<
DockState
>();
string dockState;
JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
HttpCookie positionsCookie = Request.Cookies[cookiename];
if (!Object.Equals(positionsCookie, null))
{
dockState = positionsCookie.Value;
string[] currentDockStates = dockState.Split(new Char[] { '|' });
foreach (string stringState in currentDockStates)
{
if (stringState != string.Empty)
{
DockState state = new DockState();
state = serializer.Deserialize<
DockState
>(stringState);
currentDocks.Add(state);
}
}
}
return currentDocks;
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DropDownZone.DataBind();
}
}
public ArrayList GetZones()
{
ArrayList zones = new ArrayList();
zones.Add(RadDockZone1);
zones.Add(RadDockZone2);
zones.Add(RadDockZone3);
return zones;
}
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());
return dock;
}
private RadDock CreateRadDock()
{
RadDock dock = new RadDock();
dock.DockMode = DockMode.Docked;
dock.UniqueName = Guid.NewGuid().ToString().Replace("-", "a");
dock.ID = string.Format("RadDock{0}", dock.UniqueName);
dock.Title = DroptDownWidget.SelectedItem.Text;
dock.Text = string.Format("Added at {0}", DateTime.Now);
dock.Width = Unit.Pixel(300);
dock.Commands.Add(new DockCloseCommand());
dock.Commands.Add(new DockExpandCollapseCommand());
return dock;
}
// void dock_Command(object sender, DockCommandEventArgs e)
// {
// if (e.Command.Name == "Close")
// {
// ScriptManager.RegisterStartupScript(
// UpdatePanel1,
// this.GetType(),
// "RemoveDock",
// string.Format(@"function _removeDock() {{
// Sys.Application.remove_load(_removeDock);
// $find('{0}').undock();
// $get('{1}').appendChild($get('{0}'));
// $find('{0}').doPostBack('DockPositionChanged');
//}};
//Sys.Application.add_load(_removeDock);", ((RadDock)sender).ClientID, UpdatePanel1.ClientID),
// true);
// }
// }
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;
AsyncPostBackTrigger saveStateTrigger = 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);
}
protected void Page_Init(object sender, EventArgs e)
{
List<
DockState
> CurrentDockStates = GetDocks(cookiename);
for (int i = 0; i <
CurrentDockStates.Count
; i++)
{
RadDock
dock
=
CreateRadDockFromState
(CurrentDockStates[i]);
//We will just add the RadDock control to the RadDockLayout.
// You could use any other control for that purpose, just ensure
// that it is inside the RadDockLayout control.
// The RadDockLayout control will automatically move the RadDock
// controls to their corresponding zone in the LoadDockLayout
// event (see below).
RadDockLayout1.Controls.Add(dock);
//We want to save the dock state every time a dock is moved.
CreateSaveStateTrigger(dock);
LoadWidget(dock);
}
}
protected void RadDockLayout1_LoadDockLayout(object sender, DockLayoutEventArgs e)
{
//Populate the event args with the state information. The RadDockLayout control
// will automatically move the docks according that information.
List<DockState> CurrentDockStates = GetDocks(cookiename);
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)
{
string dockState;
JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
List<
DockState
> stateList = ((RadDockLayout)sender).GetRegisteredDocksState(true);
StringBuilder serializedList = new StringBuilder();
int i = 0;
while (i < stateList.Count)
{
serializedList.Append(serializer.Serialize(stateList[i]));
serializedList.Append("|");
i++;
}
dockState = serializedList.ToString();
HttpCookie positionsCookie = new HttpCookie(cookiename, dockState);
//Ensure that the cookie will not expire soon
positionsCookie.Expires = DateTime.Now.AddYears(1);
Response.Cookies.Add(positionsCookie);
}
protected void ButtonAddDock_Click(object sender, EventArgs e)
{
RadDock dock = CreateRadDock();
//find the target zone and add the new dock there
RadDockZone dz = (RadDockZone)FindControl(DropDownZone.SelectedItem.Text);
dz.Controls.Add(dock);
CreateSaveStateTrigger(dock);
//Load the selected widget in the RadDock control
dock.Tag = DroptDownWidget.SelectedValue;
LoadWidget(dock);
//Right now the RadDock control is not docked. When we try to save its state
// later, the DockZoneID will be empty. To workaround this problem we will
// set the AutoPostBack property of the RadDock control to true and will
// attach an AsyncPostBackTrigger for the DockPositionChanged client-side
// event. This will initiate second AJAX request in order to save the state
// AFTER the dock was docked in RadDockZone1.
CreateSaveStateTrigger(dock);
}
private void LoadWidget(RadDock dock)
{
if (string.IsNullOrEmpty(dock.Tag))
{
return;
}
Control widget = LoadControl(dock.Tag);
dock.ContentContainer.Controls.Add(widget);
}
protected void ButtonPostBack_Click(object sender, EventArgs e)
{
//normal postback
}
protected void ButtonClear_Click(object sender, EventArgs e)
{
//clear docks state from the session
//CurrentDockStates.Clear();
//_dockStateCleared = true;
}
}