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

RadDocs not maintiaining new order after initial postback

1 Answer 68 Views
Dock
This is a migrated thread and some comments may be shown as answers.
J
Top achievements
Rank 1
J asked on 25 Mar 2010, 09:34 PM
I have the following RadDock on the my page and noticed that when I reorder docs the first time this new order isnt saved.  But second time thru if i preform a reorder everything sticks like its supposed to.

ASCX code:
<telerik:RadDockLayout runat="server" ID="RadDockLayout1"    
    OnLoadDockLayout="RadDockLayout1_LoadDockLayout"   
    OnSaveDockLayout="RadDockLayout1_SaveDockLayout"    
    StoreLayoutInViewState=true 
    > 
    <div id="div_rdZoneCurrentCycle">  
    <telerik:RadDockZone runat="server" ID="RadDockZone_ExistingPriorities"   
        BorderStyle="None"   
        MinHeight="30px" width="100%"   
        > 
    </telerik:RadDockZone> 
    </div> 
</telerik:RadDockLayout> 

Class code:
   public partial class SSPPrioritizePriorities : System.Web.UI.UserControl  
   {  
       private List<DockState> CurrentDockStates  
       {  
           get 
           {  
               // Store the info about the added docks in the session.  
 
               List<DockState> _currentDockStates = (List<DockState>)Session["CurrentDockStatesDynamicDocks"];  
               if (Object.Equals(_currentDockStates, null))  
               {  
                   _currentDockStates = new List<DockState>();  
                   Session["CurrentDockStatesDynamicDocks"] = _currentDockStates;  
               }  
               return _currentDockStates;  
           }  
           set 
           {  
               Session["CurrentDockStatesDynamicDocks"] = value;  
           }  
       }
       #endregion  
 
       const string TitleBarText = "TitleText";  
       const string CurrentRank = "CurRankText";  
       const string PreviousRank = "PreRankText";
       #endregion  
 
       #region " Page Load Events " 
 
       protected void Page_Load(object sender,EventArgs e)  
       {  
       }  
 
       protected override void OnInit(EventArgs e)  
       {  
           base.OnInit(e);  
 
           if (!Page.IsPostBack)  
           {  
               using (ObjectsContext context = new ObjectsContext())  
               {  
                   MyManager manager = new MyManager(context);  
 
                   CurrentCyclePriorities = manager.something.Cycle();  
                   CurrentCycleSSP = manager.somehingelse.GetCurrent(this._SSPK);  
                   PreviousCycleSSP = manager.somehingelse.GetPrevious(this._SSPK);  
                   LoadPriorities();  
                    
               }  
 
           }  
           else 
           {  
               for (int i = 0; i < CurrentDockStates.Count; i++)  
               {  
                   RadDock dock = CreateRadDockFromState(CurrentDockStates[i]);  
                   RadDockLayout1.Controls.Add(dock);  
                   CreateSaveStateTrigger(dock);  
               }  
           }  
 
           SetRadDockOrder();  
       }
       #endregion  
 
       #region " Priorities Load Events " 
 
       protected void LoadPriorities()  
       {  
           CreateRadDock(sspPrevious.Priority, truetruefalse,   
       }
       #endregion  
 
       #region " Dock Events "
       #region " Create "  
 
       private void CreateRadDock(BusinessObjects.Priority apriority, Boolean BottomDock, Boolean Closed, Boolean New, int previousRanking, int? CurrentRanking)  
       {  
            try 
            {  
                // Create the Rad Dock and set properties  
 
                RadDock dock = new RadDock();  
                dock.DockMode = DockMode.Docked;  
                dock.DockHandle = DockHandle.TitleBar;  
                dock.Collapsed = true;  
                dock.Width = Unit.Percentage(96);  
                dock.Skin = "MySkin";  
                dock.EnableEmbeddedSkins = false;  
                dock.EnableRoundedCorners = true;  
                dock.EnableAnimation = true;  
                dock.Font.Name = "Arial";  
                int intIndex = dock.Index;  
 
                dock.AutoPostBack = true;  
                dock.CommandsAutoPostBack = true;  
 
                // Create the TitleBar and add to Rad Dock  
 
                TitleBarTemplate2 tbt = new TitleBarTemplate2();  
                tbt.GenerateTitleBar(dock.TitlebarContainer, 5);  
                dock.TitlebarTemplate = tbt;  
 
                // Add Rad Dock Title information  
 
                dock.UniqueName = apriority.PK.ToString();  
                dock.ID = string.Format("rd{0}", dock.UniqueName);  
                dock.Title = "<span style=\"font-size:14px;\"><b>" + apriority.PK.ToString() + "</b></span> ";  
                ((Label)dock.TitlebarContainer.Controls[0].FindControl(TitleBarText)).Text = dock.Title;  
 
                // Add Rad Dock Previous Rank information  
 
                if (!New)  
                {  
                    String preRanking = "<span style=\"font-size:14px;\"><b>(" + previousRanking.ToString() + ")</b></span>";  
                    ((Label)dock.TitlebarContainer.Controls[0].FindControl(PreviousRank)).Text = preRanking;  
                }  
 
                // Set Rad Dock Events and Triggers  
 
                if (BottomDock)  
                    dock.OnClientDragStart = "OnClientDragStart";  
                CreateSaveStateTrigger(dock);  
 
 
                    RadDockZone_ExistingPriorities.Controls.Add(dock);  
 
            }  
 
            catch (Exception ex)  
            {  
                string s = ex.StackTrace;  
            }  
       }
       #endregion  
 
       #region " Order " 
 
       private void SetRadDockOrder()  
       {  
           foreach (RadDock dock in RadDockZone_ExistingPriorities.Docks)  
           {  
               ((Label)dock.TitlebarContainer.Controls[0].FindControl(CurrentRank)).Text = "";  
               int newRank = dock.Index + 1;  
               String newRanking = "<span style=\"font-size:14px;\"><b>" + newRank.ToString() + ".</b></span>";  
               ((Label)dock.TitlebarContainer.Controls[0].FindControl(CurrentRank)).Text = newRanking;  
           }  
       }
       #endregion  
 
       #region " States " 
 
       private RadDock CreateRadDockFromState(DockState state)  
       {  
 
           RadDock dock = new RadDock();  
 
           //// Create the TitleBar and add to Rad Dock  
 
           TitleBarTemplate2 tbt = new TitleBarTemplate2();  
           tbt.GenerateTitleBar(dock.TitlebarContainer, 5);  
           dock.TitlebarTemplate = tbt;  
 
           //// Add Rad Dock Title information  
 
           dock.UniqueName = state.UniqueName;  
           //dock.Index = state.Index;  
           dock.Title = "<span style=\"font-size:14px;\"><b>" + dock.UniqueName + "</b></span> ";  
           ((Label)dock.TitlebarContainer.Controls[0].FindControl(TitleBarText)).Text = state.Title;  
 
           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;  
       }  
 
       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;  
           }  
       }  
 
       protected void RadDockLayout1_SaveDockLayout(object sender, DockLayoutEventArgs e)  
       {  
           CurrentDockStates = new List<DockState>();  
           foreach (DockState ds in RadDockLayout1.GetRegisteredDocksState())  
           {  
               CurrentDockStates.Add(ds);  
           }  
       }
       #endregion  
 
       #endregion  
 
   } 

Again, the problem is that initially the page loads the dynamically created RadDocs in thier correct order.  I move the bottom most doc to the be the top most doc and the page posts back.  Ok so while the page posts back, the order doenst change and mr bottom doc remains on the bottom.  BUT!!! if i reorder AFTER the first post back, the docs retain thier placement.

J

1 Answer, 1 is accepted

Sort by
0
Pero
Telerik team
answered on 31 Mar 2010, 09:07 AM
Hi,

I couldn't run the code as is. That's why I made some modifications, and managed to run it. However, I didn't experience any problems with positioning of the docks.Here is the code for you to test. Please, modify it accordingly, so the problem is reproduced, and send it back.

Please note that, the LoadDockLayout event is fired immediately after the Page.InitComplete, and if the user control is loaded dynamically, it should be added in the Page.Init or LoadDockLayout will not be fired.

.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">
<head id="Head1" runat="server">
    <title></title>
    <style type="text/css">
        .RadDockZone
        {
            float: left;
            margin-right: 10px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
        <Scripts>
            <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" />
        </Scripts>
    </asp:ScriptManager>
    <div>
        <telerik:RadDockLayout ID="RadDockLayout1" runat="server" OnLoadDockLayout="RadDockLayout1_LoadDockLayout"
            OnSaveDockLayout="RadDockLayout1_SaveDockLayout">
            <telerik:RadDockZone ID="RadDockZone1" runat="server" MinHeight="300px" Width="300px">
            </telerik:RadDockZone>
            <telerik:RadDockZone ID="RadDockZone2" runat="server" MinHeight="300px" Width="300px">
            </telerik:RadDockZone>
        </telerik:RadDockLayout>
    </div>
    </form>
</body>
</html>

.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;
 
public partial class CreateDocksDynamically : System.Web.UI.Page
{
    private List<DockState> CurrentDockStates
    {
        get
        {
            // Store the info about the added docks in the session. 
 
            List<DockState> _currentDockStates = (List<DockState>)Session["CurrentDockStatesDynamicDocks"];
            if (Object.Equals(_currentDockStates, null))
            {
                _currentDockStates = new List<DockState>();
                Session["CurrentDockStatesDynamicDocks"] = _currentDockStates;
            }
            return _currentDockStates;
        }
        set
        {
            Session["CurrentDockStatesDynamicDocks"] = value;
        }
    }
 
 
    const string TitleBarText = "TitleText";
    const string CurrentRank = "CurRankText";
    const string PreviousRank = "PreRankText";
 
 
    protected void Page_Load(object sender, EventArgs e)
    {
    }
 
    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);
 
        if (!Page.IsPostBack)
        {
            for (int i = 0; i < 5; i++)
            {
                RadDock dock = CreateRadDock(i);
                if (i % 2 == 0)
                {
                    RadDockZone1.Controls.Add(dock);
                }
                else
                {
                    RadDockZone2.Controls.Add(dock);
                }
            }
        }
        else
        {
            for (int i = 0; i < CurrentDockStates.Count; i++)
            {
                RadDock dock = CreateRadDockFromState(CurrentDockStates[i]);
                RadDockLayout1.Controls.Add(dock);
                CreateSaveStateTrigger(dock);
            }
        }
 
 
    }
 
    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());
 
        dock.AutoPostBack = true;
        dock.CommandsAutoPostBack = true;
 
        return dock;
    }
 
    private RadDock CreateRadDock(int i)
    {
        RadDock dock = new RadDock();
        dock.DockMode = DockMode.Docked;
        dock.UniqueName = Guid.NewGuid().ToString();
        dock.ID = string.Format("RadDock{0}", dock.UniqueName);
        dock.Title = "Dock" + i.ToString();
        dock.Text = string.Format("Added at {0}", DateTime.Now);
        dock.Width = Unit.Pixel(300);
        dock.AutoPostBack = true;
        dock.CommandsAutoPostBack = true;
 
        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;
    }
 
    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;
        }
    }
 
    protected void RadDockLayout1_SaveDockLayout(object sender, DockLayoutEventArgs e)
    {
        CurrentDockStates = new List<DockState>();
        foreach (DockState ds in RadDockLayout1.GetRegisteredDocksState())
        {
            CurrentDockStates.Add(ds);
        }
    }
}



Kind regards,
Pero
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
Dock
Asked by
J
Top achievements
Rank 1
Answers by
Pero
Telerik team
Share this question
or