Dear All,
I am saving the state of the docks in the database. Everything works, but if a user leaves the page and comes back to it
niether Close nor Minimize buttons are working. CreateRadDockFromState does add commands DockCloseCommand and
DockExpandCollapseCommand :
Any ideas?
Thank you.
I am saving the state of the docks in the database. Everything works, but if a user leaves the page and comes back to it
niether Close nor Minimize buttons are working. CreateRadDockFromState does add commands DockCloseCommand and
DockExpandCollapseCommand :
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;
}
Any ideas?
| using System; |
| using System.Collections; |
| using System.Collections.Generic; |
| using System.Linq; |
| using System.Web; |
| using System.Web.UI; |
| using System.Web.UI.WebControls; |
| using Campus.AppCode; |
| using Campus.AppCode.BusinessLayer; |
| using Telerik.Web.UI; |
| namespace Campus.Development |
| { |
| public partial class DevelopmentProfile : System.Web.UI.Page |
| { |
| private bool _dockStateCleared = false; |
| private List<DockState> CurrentDockStates |
| { |
| get |
| { |
| var _currentDockStates = new List<DockState>(); |
| String strCookieName = "dockstates"; |
| HttpCookie cookie = Request.Cookies[strCookieName]; |
| if (cookie == null) |
| { |
| string possibleSettings = new BLLAspNetUser().GetUserSetting(strCookieName); |
| if (!String.IsNullOrEmpty(possibleSettings)) |
| _currentDockStates = new BLLAspNetUser().DeSerializeDockStates(possibleSettings); |
| else |
| _currentDockStates = new List<DockState>(); |
| string serializedString = new BLLAspNetUser().SerializeDockStates(_currentDockStates); |
| AddCookie(serializedString); |
| } |
| else |
| { |
| _currentDockStates = |
| new BLLAspNetUser().DeSerializeDockStates(Server.HtmlDecode(Base64Encoder.base64Decode(cookie.Value))); |
| } |
| return _currentDockStates; |
| } |
| set |
| { |
| string serializedString = new BLLAspNetUser().SerializeDockStates(value); |
| AddCookie(serializedString); |
| new BLLAspNetUser().SetUserSetting("dockstates", serializedString); |
| } |
| } |
| private void AddCookie(string value) |
| { |
| HttpCookie cookie = new HttpCookie("dockstates"); |
| cookie.Value = Server.HtmlEncode(Base64Encoder.base64Encode(value)); |
| DateTime dtNow = new BLLSchoolInfo().GetSqlDate(); |
| TimeSpan tsMinute = new TimeSpan(1000000, 0, 0, 0); |
| cookie.Expires = dtNow + tsMinute; |
| Response.Cookies.Add(cookie); |
| } |
| protected void Page_Load(object sender, EventArgs e) |
| { |
| if (!IsPostBack) |
| { |
| DropDownZone.DataBind(); |
| } |
| } |
| protected void Page_Init(object sender, EventArgs e) |
| { |
| //Recreate the docks in order to ensure their proper operation |
| for (int i = 0; i < CurrentDockStates.Count; i++) |
| { |
| if (CurrentDockStates[i].Closed == false) |
| { |
| 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); |
| //Load the selected widget |
| 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. |
| 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) |
| { |
| if (!_dockStateCleared) |
| { |
| //Save the dock state in the session. This will enable us |
| // to recreate the dock in the next Page_Init. |
| CurrentDockStates = RadDockLayout1.GetRegisteredDocksState(); |
| } |
| else |
| { |
| //the clear state button was clicked, so we refresh the page and start over. |
| Response.Redirect(Request.RawUrl, false); |
| } |
| } |
| 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(string dockName) |
| { |
| RadDock dock = new RadDock(); |
| dock.DockMode = DockMode.Docked; |
| dock.UniqueName = Guid.NewGuid().ToString(); |
| dock.ID = string.Format("RadDock{0}", dock.UniqueName); |
| dock.Title = dockName; |
| dock.Text = string.Format("Added at {0}", DateTime.Now); |
| dock.Width = Unit.Percentage(100); |
| 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; |
| 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); |
| } |
| private void LoadWidget(RadDock dock) |
| { |
| if (string.IsNullOrEmpty(dock.Tag)) |
| { |
| return; |
| } |
| Control widget = LoadControl(dock.Tag); |
| dock.ContentContainer.Controls.Add(widget); |
| } |
| protected void ButtonAddDock_Click(object sender, EventArgs e) |
| { |
| RadDock dock = CreateRadDock(DroptDownWidget.SelectedItem.Text); |
| //find the target zone and add the new dock there |
| RadDockZone dz = (RadDockZone)(this.DropDownZone.FindControl(DropDownZone.SelectedItem.Text)); |
| dz.Controls.Add(dock); |
| CreateSaveStateTrigger(dock); |
| //Load the selected widget in the RadDock control |
| dock.Tag = DroptDownWidget.SelectedValue; |
| LoadWidget(dock); |
| } |
| public ArrayList GetZones() |
| { |
| ArrayList zones = new ArrayList(); |
| zones.Add(Left); |
| zones.Add(Right); |
| return zones; |
| } |
| } |
| } |
| <%@ Page Title="Developer Profile" Language="C#" MasterPageFile="~/MasterPages/Development.Master" |
| ValidateRequest="false" AutoEventWireup="true" CodeBehind="DevelopmentProfile.aspx.cs" |
| Inherits="Campus.Development.DevelopmentProfile" %> |
| <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> |
| <%@ Register Src="Controls/DeveloperCalendar.ascx" TagName="DeveloperCalendar" TagPrefix="uc1" %> |
| <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server"> |
| </asp:Content> |
| <asp:Content ID="Content2" ContentPlaceHolderID="contentpane" runat="server"> |
| <asp:ScriptManager ID="ScriptManager1" runat="server"> |
| </asp:ScriptManager> |
| <div> |
| <asp:UpdatePanel runat="server" ID="UpdatePanel2"> |
| <ContentTemplate> |
| <br /> |
| <telerik:RadDockLayout runat="server" ID="RadDockLayout1" OnSaveDockLayout="RadDockLayout1_SaveDockLayout" |
| OnLoadDockLayout="RadDockLayout1_LoadDockLayout" Skin="WebBlue"> |
| <telerik:RadDockZone runat="server" ID="Left" Width="45%" MinHeight="200" Style="float: left; |
| margin-right: 15px; background: #f5f4e8;"> |
| </telerik:RadDockZone> |
| <telerik:RadDockZone runat="server" ID="Right" Width="45%" MinHeight="200" Style="background: #f5f4e8; |
| float: left;"> |
| </telerik:RadDockZone> |
| </telerik:RadDockLayout> |
| </ContentTemplate> |
| <Triggers> |
| <asp:AsyncPostBackTrigger ControlID="ButtonAddDock" EventName="Click" /> |
| </Triggers> |
| </asp:UpdatePanel> |
| <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> |
| <%--<table width="100%" height="768px"> |
| <tr height="384px"> |
| <td valign="top" width="50%"> |
| <uc1:DeveloperCalendar ID="DeveloperCalendar1" runat="server" /> |
| </td> |
| <td valign="top" width="50%"> |
| </td> |
| </tr> |
| <tr> |
| <td valign="top" width="50%"> |
| </td> |
| <td valign="top" width="50%" height="100%"> |
| </td> |
| </tr> |
| </table>--%> |
| </div> |
| <br /> |
| <div style="clear: both"> |
| Select Module: |
| <asp:DropDownList runat="server" ID="DroptDownWidget" Width="150"> |
| <asp:ListItem Text="Calendar" Value="~/Development/Controls/DeveloperCalendar.ascx" |
| Selected="true"></asp:ListItem> |
| </asp:DropDownList> |
| Select Docking Zone: |
| <asp:DropDownList ID="DropDownZone" runat="server" DataSource="<%#GetZones() %>" |
| DataTextField="ID" DataValueField="ClientID" Width="150"> |
| </asp:DropDownList> |
| <asp:Button runat="server" CssClass="button" ID="ButtonAddDock" Text="Add Dock" OnClick="ButtonAddDock_Click" /> |
| </div> |
| </asp:Content> |
Thank you.