This is a migrated thread and some comments may be shown as answers.

radDock Close and Minimize Problem AFTER reload/save

6 Answers 158 Views
Dock
This is a migrated thread and some comments may be shown as answers.
debett
Top achievements
Rank 1
debett asked on 13 May 2009, 09:33 PM
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 :

 

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> 
        &nbsp;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.

6 Answers, 1 is accepted

Sort by
0
Obi-Wan Kenobi
Top achievements
Rank 1
answered on 14 May 2009, 12:48 PM
The MyPortal example is almost the same as yours and it works. The only one difference is that the DockState is stored in session.
The problem could be in some other place(in code which is in MasterPage) so you should try to isolate the page(without MasterPage) to work only with RadDocks and see if it will work.  Do you have JavaScript errors on the page If the Close and Expand commands don't work?


0
debett
Top achievements
Rank 1
answered on 14 May 2009, 01:39 PM

Dear Obi-Wan Kenobi ,

It's interesting that I copied the whole example and it didn't work for session either.

Yes, there is javascript error:

Webpage error details

User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET CLR 1.1.4322; InfoPath.1; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)
Timestamp: Thu, 14 May 2009 13:37:43 UTC

Message: Expected ':'
Line: 365
Char: 728
Code: 0
URI: http://localhost:4031/Default.aspx

 

Thank you.

0
debett
Top achievements
Rank 1
answered on 14 May 2009, 02:12 PM
I tried it with no master page and with session only - did not work.
Also the control is not movable. So it's being displayed as an image..
All that happens after postback.
0
debett
Top achievements
Rank 1
answered on 14 May 2009, 03:56 PM
You can try it here:
https://webapps.pcrsoft.com/testCampus/Development/DevelopmentProfile.aspx

login: telerik
password: telerik

These are the simptoms:
- Controls are dragable, closable and minimizable right after they are added to the page
- Controls are NOT dragable, closable and minimizable right after any postback
- Controls are dragable, closable and minimizable AGAIN if a new control was added, so in other words,
if I add a control to the page - it's working, after a postback - it's not working, if i add another control again - all the controls will be working..

Thank you.
0
debett
Top achievements
Rank 1
answered on 15 May 2009, 01:08 PM
Just tried to create a new project and have some results.
I copied the code from http://demos.telerik.com/aspnet-ajax/dock/examples/forbiddenzones/defaultcs.aspx exactly like you guys have it.
So It did not work. But it did not work when the control being added to the dock is Telerik Scheduler.
It works with VS controls, but not telerik. Please, see the exaple project attached.
0
Petio Petkov
Telerik team
answered on 15 May 2009, 02:31 PM
Hello debett,

The RadDock has an ID which contains '-', but ASP.NET controls can't work when they has "-" in the ID. This causes RadCalendar to throw an error and RadDock stops to work correctly.
Could you please try to use:
dock.UniqueName = Guid.NewGuid().ToString().Replace('-','a');
instead:
dock.UniqueName = Guid.NewGuid().ToString();
and everything should be fine.
We will also change the MyPortal example to not create RadDocks with ID which contains '-'.
Let us know if you have any other questions.


Greetings,
Petio Petkov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Dock
Asked by
debett
Top achievements
Rank 1
Answers by
Obi-Wan Kenobi
Top achievements
Rank 1
debett
Top achievements
Rank 1
Petio Petkov
Telerik team
Share this question
or