Tracking dynamically created panes

3 posts, 1 answers
  1. Sean
    Sean avatar
    200 posts
    Member since:
    Nov 2010

    Posted 15 Jun 2011 Link to this post

    Hi Telerik,

    I was wondering what the prescribed method is for tracking dynamically created panes. I have been working with RadDockLayout for some time and am wondering if it is possible to write an extension method that gives it the ability to keep track of the Panes on the page?

    Let me shed some light on some of my issues:

    There are a bunch of splitters and panes on the page. The user resizes them and I need to save the state of the controls through page refresh at this point. I am doing this by firing an ajax event on pane resized and then saving the states of all the panes.

    public static void SavePanes()
    {
        foreach (KeyValuePair<string, RadPaneSetting> paneState in GetStates<SerializableDictionary<string, RadPaneSetting>>().ToList())
        {
            CormantRadPane pane = Utilities.FindControlRecursive(HttpContext.Current.Handler as Page, paneState.Key) as CormantRadPane;
            Save<RadPaneSetting>(pane);
        }
    }

    The Utilities.FindControlRecurisve is just that, a recursive implementation of Page.FindControl. It is slow when there are large amounts of controls on the page, and I do not like calling it more than I absolutely have to, but I do not have a nice collection of monitored RadPanes already.

    As such, I created a manager class for regenerating my controls.

    public class RegenerationManager
        {
            private static readonly ILog Logger = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
     
            private static readonly RegenerationManager instance = new RegenerationManager();
            private RegenerationManager() { }
     
            public static RegenerationManager Instance
            {
                get { return instance; }
            }
     
            private IList<CormantRadPane> _regeneratedPanes;
     
            //Don't monitor RadDockZone or RadDock -- these are handled by RadDockLayout.
     
            public IList<CormantRadPane> RegeneratedPanes
            {
                get
                {
                    if (object.Equals(_regeneratedPanes, null))
                    {
                        _regeneratedPanes = new List<CormantRadPane>();
                    }
     
                    return _regeneratedPanes;
                }
            }
     
            /// <summary>
            /// Recreates the page state recursively by creating a control and looking for its known children.
            /// </summary>
            /// <param name="splitter"> Splitter having children added to it. </param>
            private void RegenerateSplitterChildren(RadSplitter splitter)
            {
                Logger.InfoFormat("Initializing splitter children for splitter {0}", splitter.ID);
                foreach (KeyValuePair<string, RadPaneSetting> paneState in RadControlManager.GetStates<SerializableDictionary<string, RadPaneSetting>>().Where(paneState => paneState.Value.ParentID == splitter.ID))
                {
                    CormantRadPane pane = new CormantRadPane(paneState.Value);
                    RegeneratedPanes.Add(pane);
                    splitter.Controls.Add(pane);
                    RegeneratePaneChildren(pane);
                    InsertSplitBar(splitter);
                }
            }
     
            /// <summary>
            /// Recreates all the dynamically made DockZones.
            /// </summary>
            public void RegenerateDockZones()
            {
                Logger.Info("Regenerating dock zones.");
                foreach (KeyValuePair<string, RadDockZoneSetting> dockZoneState in RadControlManager.GetStates<SerializableDictionary<string, RadDockZoneSetting>>())
                {
                    try
                    {
                        RadDockZoneSetting dockZoneSetting = dockZoneState.Value as RadDockZoneSetting;
                        if (dockZoneSetting.ID == "RadDockZone1") continue;
                        Logger.Info(String.Format("Loading state data for dock zone with setting ID: {0}", dockZoneSetting.ID));
                        CormantRadDockZone dockZone = new CormantRadDockZone(dockZoneSetting);
                        //CormantRadPane pane = RegeneratedPanes.First(regeneratedPane => regeneratedPane.ID == dockZoneSetting.ParentID);
                        CormantRadPane pane = Utilities.FindControlRecursive(HttpContext.Current.Handler as Page, dockZoneSetting.ParentID) as CormantRadPane;
                        pane.Controls.Add(dockZone);
                    }
                    catch (Exception exception)
                    {
                        System.Diagnostics.Debug.Assert(false, "Error!");
                        Logger.ErrorFormat("Error regenerating dock zones. Reason: {0}", exception.Message);
                    }
                }
            }

    If you would kindly look at the above "RegeneratedDockZones" function you will see that I have commented out my attempt at regenerating from my own list. While I seem to find the control just fine I noticed a lot of very weird problems occurring with my dashboard after attempting to load from "RegeneratedPanes". Yet, you can see in RegenerateSplitterChildren that I am working with the same pane which was already existing on the page / being recreated upon the splitter.

    Do you see anything erroneous with this? Or anything I should be doing differently? I only have need to monitor RadPanes at this point in time, I was hoping this would be rather simple.. 
  2. Answer
    Niko
    Admin
    Niko avatar
    387 posts

    Posted 16 Jun 2011 Link to this post

    Hi Sean,

    At a first look the code appears correct. Still I will need to see it incorporated in a small runnable sample project in order to check the glitches that you are referring to and try to investigate what may be causing them. Therefore I should advise you to open a support ticket and attach the project there. Also I suppose you have gone through the help article about Dynamically Creating RadDock Controls, as it is a good example of storing and retrieving the state of dynamically created control.

    Greetings,
    Niko
    the Telerik team

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Sean
    Sean avatar
    200 posts
    Member since:
    Nov 2010

    Posted 20 Jun 2011 Link to this post

    I went ahead and bumped this into an open ticket. Thanks.
Back to Top