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

Dynamically RadDock Controls problems

4 Answers 76 Views
Dock
This is a migrated thread and some comments may be shown as answers.
Cátia
Top achievements
Rank 1
Cátia asked on 15 Jun 2009, 11:48 AM
Hi,

I tried to add code to define the position to the several docks that I have on the same page, but I'm having some problems.
I used the example on this link: http://www.telerik.com/help/aspnet-ajax/dock_dockcontrolcreation.html because it's similar to what I want to create, but it doesn't work.
My intention is, on the same page, have several docks that are in .ascx files.
On the default page I have a radDockLayout and inside this control I have the .ascx files:

<

 

telerik:RadDockLayout ID="RadDockLayout1" runat="server" OnSaveDockLayout="RadDockLayout1_SaveDockLayout" OnLoadDockLayout="RadDockLayout1_LoadDockLayout">

 

 

<uc5:barraLateral ID="BarraLateral1" runat="server" />

 

 

<uc2:TodosConteudos ID="TodosConteudos1" runat="server" />

 

 

<uc3:MeusConteudos ID="MeusConteudos1" runat="server" />

 

 

<uc4:UltimosConteudos ID="UltimosConteudos1" runat="server" />

 

 

</telerik:RadDockLayout>

 



And in the default code page I have the following code:

using

 

System;

 

using

 

System.Collections;

 

using

 

System.Collections.Generic;

 

using

 

System.ComponentModel;

 

using

 

System.Data;

 

using

 

System.Drawing;

 

using

 

System.Web;

 

using

 

System.Web.SessionState;

 

using

 

System.Web.UI;

 

using

 

System.Web.UI.WebControls;

 

using

 

System.Web.UI.HtmlControls;

 

using

 

Telerik.Web.UI;

 

public

 

partial class _Default : System.Web.UI.Page

 

{

 

protected void Page_Load(object sender, EventArgs e)

 

{

}

 

 

//Store the info about the added docks in the session.

 

 

private List<DockState> CurrentDockStates

 

{

 

get

 

{

 

List<DockState> _currentDockStates = (List<DockState>)Session["CurrentDockStates"];

 

 

if (Object.Equals(_currentDockStates, null))

 

{

_currentDockStates =

new List<DockState>();

 

Session[

"CurrentDockStates"] = _currentDockStates;

 

}

 

return _currentDockStates;

 

}

 

set

 

{

Session[

"CurrentDockStates"] = value;

 

}

}

 

protected void RadDockLayout1_SaveDockLayout(object sender, DockLayoutEventArgs e)

 

{

CurrentDockStates = RadDockLayout1.GetRegisteredDocksState();

}

 

protected void Page_Init(object sender, EventArgs e)

 

{

 

for (int i = 0; i < CurrentDockStates.Count; i++)

 

{

 

RadDock dock = new RadDock();

 

dock.ID =

string.Format("RadDock{0}", i);

 

dock.ApplyState(CurrentDockStates[i]);

RadDockLayout1.Controls.Add(dock);

}

}

 

protected void RadDockLayout1_LoadDockLayout(object sender, DockLayoutEventArgs e)

 

{

 

foreach (DockState state in CurrentDockStates)

 

{

e.Positions[state.UniqueName] = state.DockZoneID;

e.Indices[state.UniqueName] = state.Index;

}

}

}



I don't want to create new docks, I just want to save the position of the docks that are on those .ascx files, but I can't save because they are not on the default page. How can I solve this problem without copy all the code from the .ascx files to the defaul page?

4 Answers, 1 is accepted

Sort by
0
Pero
Telerik team
answered on 18 Jun 2009, 10:23 AM
Hi Cátia,

From the source code of your project I see that you have created docks in .ascx files and then you added them to the .aspx page. When you create RadDocks in design time you do not need to save their state in the code behind. The RadDockLayout saves it for you. So when you try to save their state and load it on a postback you will get RadDocks with the same IDs, which will cause an exception.

For your convenience I have created a demo project that uses WebControls (.ascx) to create the docks and added them on the DockLayout. It is attached to the thread.


Kind regards,
Pero
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.
0
Cátia
Top achievements
Rank 1
answered on 18 Jun 2009, 10:57 AM
Hi!
Thanks for your help, but I think I didn't explained exactly what I want.
The RadDockLayout was already in my project and everything was working like you said on your post. But I would like that when a user who is authenticated on the website could have the ability to move the docks and when he navigates to other pages and returns to the default page (where the docks are), the position of the docks are exactly as the last time he moved them.
Sorry for this misunderstood, hope you can have a solution for this problem.
Thanks.
0
Accepted
Pero
Telerik team
answered on 23 Jun 2009, 03:20 PM
Hi Cátia,

Two possible scenarios exist:

 - The user navigates to a different website - When this is the case the state of the RadDocks should not be saved in the Session, because it is destroyed. So, cookies or database should be used instead.

 - The user navigates to a different page (within the same website) - When this is the case the session is not destroyed and the state can be saved in the session. I have implemented a sample project that demonstrates this behavior. The idea behind is to put the RadDocks in an update panel and set their AutoPostBack properties to true. Because, when any of the docks change their position, a post back is needed to save their state on the server. Please note that there is no need to recreate the docks on Page_Init because they are already created in design time. I have added a new Default2.aspx page to the same project and made a couple of changes to .aspx and .cs file so I am pasting the code directly in the thread.

Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="DockDynamically219759._Default" %> 
 
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> 
<%@ Register TagPrefix="dock" TagName="content" Src="DockContent.ascx" %> 
<%@ Register TagPrefix="dock1" TagName="content1" Src="DockContent1.ascx" %> 
<!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 runat="server"
    <title></title
</head> 
<body> 
    <form id="form1" runat="server"
    <asp:ScriptManager ID="ScriptManager1" runat="server"
    </asp:ScriptManager> 
    <div> 
        <href="Default2.aspx">Default2.aspx</a> 
        <telerik:RadDockLayout runat="server" ID="RadDockLayout1"  
            OnLoadDockLayout="RadDockLayout1_LoadDockLayout" 
            OnSaveDockLayout="RadDockLayout1_SaveDockLayout"
           <asp:UpdatePanel ID="UpdatePanel1" runat="server"
            <ContentTemplate> 
                <dock:content ID="dockContent" runat="server" /> 
                <dock1:content1 ID="Content1" runat="server" /> 
            </ContentTemplate> 
           </asp:UpdatePanel>  
             
        </telerik:RadDockLayout> 
        <asp:Button ID="btnPostback" runat="server" Text="Make PostBack" /> 
    </div> 
    </form> 
</body> 
</html> 
 


Default2.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default2.aspx.cs" Inherits="DockDynamically219759.Default2" %> 
 
<!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 runat="server"
    <title></title
</head> 
<body> 
    <form id="form1" runat="server"
    <div> 
    <href="Default.aspx">Default.aspx</a> 
    </div> 
    </form> 
</body> 
</html> 

Default.aspx.cs
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; 
 
namespace DockDynamically219759 
    public partial class _Default : System.Web.UI.Page 
    { 
        protected void Page_Load(object sender, EventArgs e) 
        { 
 
        } 
 
        private List<DockState> CurrentDockStates 
        { 
            get 
            { 
                List<DockState> _currentDockStates = (List<DockState>)Session["CurrentDockStates"]; 
                if (Object.Equals(_currentDockStates, null)) 
                { 
                    _currentDockStates =new List<DockState>(); 
                    Session["CurrentDockStates"] = _currentDockStates; 
                } 
                return _currentDockStates; 
            } 
            set 
            { 
                Session["CurrentDockStates"] = value; 
            } 
        } 
        protected void RadDockLayout1_SaveDockLayout(object sender, DockLayoutEventArgs e) 
        { 
           CurrentDockStates = RadDockLayout1.GetRegisteredDocksState(); 
        } 
         
        protected void RadDockLayout1_LoadDockLayout(object sender, DockLayoutEventArgs e) 
        { 
 
            foreach (DockState state in CurrentDockStates) 
            { 
                e.Positions[state.UniqueName] = state.DockZoneID; 
                e.Indices[state.UniqueName] = state.Index; 
 
            } 
 
        } 
         
    } 
 


Best wishes,
Pero
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.
0
Cátia
Top achievements
Rank 1
answered on 24 Jun 2009, 10:43 AM
Thanks a lot.
It just worked fine :)
Tags
Dock
Asked by
Cátia
Top achievements
Rank 1
Answers by
Pero
Telerik team
Cátia
Top achievements
Rank 1
Share this question
or