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

client side saving

4 Answers 101 Views
Dock
This is a migrated thread and some comments may be shown as answers.
Matt
Top achievements
Rank 1
Matt asked on 20 Oct 2008, 09:12 AM
Hi

I want to be able to save the state of the radDock whenver I move a dock to a different position, I don't want to do a postback of the page I want an Ajax routine to do the save.
What would be the best way to do this?

Thanks
Matt

4 Answers, 1 is accepted

Sort by
0
Obi-Wan Kenobi
Top achievements
Rank 1
answered on 20 Oct 2008, 10:27 AM
A simple example which illustrates how to save the state of dynamically created RadDocks via AJAX is available here:
http://demos.telerik.com/ASPNET/Prometheus/Dock/Examples/MyPortal/DefaultCS.aspx

0
Matt
Top achievements
Rank 1
answered on 20 Oct 2008, 10:51 AM
Sorry, but I'm having trouble getting it to work, I don't want to load docks dynamically, I just want their positions to be saved when they are moved, do you have a simple example to show this?

Thanks
0
Obi-Wan Kenobi
Top achievements
Rank 1
answered on 21 Oct 2008, 01:45 PM
A simple example which illustrates how to save RadDock state on postback is available here:
http://demos.telerik.com/ASPNET/Prometheus/Dock/Examples/LoadSaveLayout/DefaultCS.aspx

To achieve your goal you should wrap the RadDockLayout with UpdatePanel and set RadDock.AutoPostback to true(position will be saved on each raddock move),e.g.
ASPX:
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
 
<html xmlns="http://www.w3.org/1999/xhtml" > 
<head id="Head1" runat="server">  
    <title>Untitled Page</title> 
</head> 
<body> 
    <form id="form1" runat="server">  
    <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager> 
    <div> 
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">  
        <ContentTemplate> 
    <telerik:RadDockLayout ID="RadDockLayout1" runat="server" 
    OnLoadDockLayout="RadDockLayout1_LoadDockLayout" 
    OnSaveDockLayout="RadDockLayout1_SaveDockLayout" 
    > 
        <telerik:RadDockZone ID="RadDockZone1" runat="server">  
            <telerik:RadDock ID="RadDock1" runat="server" Title="RadDock1" AutoPostBack="true"/>  
            <telerik:RadDock ID="RadDock2" runat="server" Title="RadDock2" AutoPostBack="true"/>  
        </telerik:RadDockZone> 
        <telerik:RadDockZone ID="RadDockZone2" runat="server">  
            <telerik:RadDock ID="RadDock3" runat="server" Title="RadDock3" AutoPostBack="true"/>  
        </telerik:RadDockZone> 
    </telerik:RadDockLayout> 
    </ContentTemplate> 
    </asp:UpdatePanel> 
    </div> 
    </form> 
</body> 
</html> 
Codebehind:
 protected void RadDockLayout1_SaveDockLayout(object sender, Telerik.Web.UI.DockLayoutEventArgs e)  
        {  
            // Store the positions in a cookie. Note, that if there are lots of dock objects on the page  
            // the cookie length might become insufficient. In this case it would be better to use the   
            // cookie to store a key from a database, where the positions will be actually stored.  
            //  
            // You can store the positions directly in a database and use the ID of the currently logged   
            // user as a key to his personalized positions.  
            JavaScriptSerializer serializer = new JavaScriptSerializer();  
            string serializedPositions = serializer.Serialize(e.Positions);  
            string serializedIndices = serializer.Serialize(e.Indices);  
 
            HttpCookie positionsCookie = new HttpCookie("DockLayout",   
                serializer.Serialize(new string[] { serializedPositions, serializedIndices }));  
 
            //Ensure that the cookie will not expire soon  
            positionsCookie.Expires = DateTime.Now.AddYears(1);  
            Response.Cookies.Add(positionsCookie);  
        }  
 
        protected void RadDockLayout1_LoadDockLayout(object sender, Telerik.Web.UI.DockLayoutEventArgs e)  
        {  
            HttpCookie positionsCookie = Request.Cookies["DockLayout"];  
            if (!Object.Equals(positionsCookie, null))  
            {  
                string serializedPositionsAndIndices = positionsCookie.Value;  
                if (!string.IsNullOrEmpty(serializedPositionsAndIndices))  
                {  
                    JavaScriptSerializer serializer = new JavaScriptSerializer();  
                    string[] positionsAndIndices = serializer.Deserialize<string[]>(serializedPositionsAndIndices);  
 
                    e.Positions = serializer.Deserialize<Dictionary<stringstring>>(positionsAndIndices[0]);  
                    e.Indices = serializer.Deserialize<Dictionary<stringint>>(positionsAndIndices[1]);  
                }  
            }  
        } 

0
Matt
Top achievements
Rank 1
answered on 21 Oct 2008, 01:49 PM
That works great, thankyou
Tags
Dock
Asked by
Matt
Top achievements
Rank 1
Answers by
Obi-Wan Kenobi
Top achievements
Rank 1
Matt
Top achievements
Rank 1
Share this question
or