Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7927851
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T19:32:00+00:00 2026-06-03T19:32:00+00:00

I have a class called LayoutManager. The purpose of this class is to hold

  • 0

I have a class called LayoutManager. The purpose of this class is to hold references to objects which are currently represented on my ASP.NET page. I originally created this class because I was experiencing a large amount of frustration with Page.FindControl(). My frustrations were two-fold:

  • Page.FindControl() in its native implementation only searches through direct children of Page. A recursive implementation is necessary in order to find any given control on Page. I was opposed to this for performance reasons.
  • In order to call Page.FindControl all of my classes in question need to know of Page. This seemed like a large amount of coupling and I was trying to mitigate that with a middle-man class.

As such, I created the class shown below. I am just now seeing how poor my implementation is. I’ve removed methods which do the same work but on different objects to simplify this example:

/// <summary>
/// This class manages controls which are present on the page.
/// Whenever a control is created it notifies this manager that it has been
/// created (inside of its constructor). At that point, you can use this
/// manager to find controls on the dashboard. 
/// The only other option is to use Page.FindControl, but its pretty broken and slow.
/// </summary>
public class LayoutManager
{
    private static readonly ILog _logger = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);

    private static readonly LayoutManager _instance = new LayoutManager();
    private LayoutManager() { }

    public static LayoutManager Instance
    {
        get { return _instance; }
    }

    //HashSets for efficiency. As long as order doesn't matter, use these.
    private HashSet<CormantRadDock> _registeredDocks;

    public RadMultiPage MultiPage { get; set; }
    public CormantTimer Timer { get; set; }
    public DashboardUpdatePanel MultiPageUpdatePanel { get; set; }
    public CormantRadTabStrip TabStrip { get; set; }
    public RadListBox TabsListBox { get; set; }
    public UpdatePanel GlobalSettingsUpdatePanel { get; set; }

    public HashSet<CormantRadDock> RegisteredDocks
    {
        get
        {
            if (Equals(_registeredDocks, null))  
                _registeredDocks = new HashSet<CormantRadDock>();
            return _registeredDocks;
        }
    }

    public CormantRadDock GetDockByID(string dockID)
    {
        CormantRadDock dock = RegisteredDocks.FirstOrDefault(registeredZone => dockID.Contains(registeredZone.ID));

        if (Equals(dock, null))
            _logger.ErrorFormat("Did not find dock: {0}", dockID);
        else
            _logger.DebugFormat("Found dock: {0}", dockID);

        return dock;
    }
}

So, a couple of things:

  • I messed up big time. This class can’t be static. Multiple users are able to place expectations on LayoutManager to return their RegisteredDocks — but this is causing data collisons.
  • I’m exposing my RegisteredDocks collection to the outside world instead of providing methods to interact with a privately-owned collection. As such, I call RegisteredDocks.Add(dock) throughout code… I am currently in the process of adding methods such as LayoutManager.AddDock(dock) which will allow me to keep the collections private and only expose methods to interact with the collections.
  • I started throwing into the class any other ‘1-of’ objects which I needed references to.

This all stems from the fact that I did not want to use Page.FindControl…. so I am feeling pretty silly now.

My questions:

  • Should I be afraid of using a recursive implementation of Page.FindControl? This link highlights my concern — the response given is the route I chose to follow.
  • What’s a solid solution if I should not be using Page.FindControl? The only simple solution which comes to my mind is storing my collections in Session and having LayoutManager continue to be static. In this implementation it would go out to Session (which changes based on user) and return the correct collection… but I am wary of saving too much data in Session as well as the cost of constantly writing back to Session.

EDIT:

Final thoughts:

public static Dashboard GetInstance()
{
    var dashboard = HttpContext.Current.Handler as Dashboard;
    //TODO: Handle case where dashboard is null.
    return dashboard;
}

public Control FindControlRecursive(Control root, string id)
{
    if (root.ID == id)
        return root;

    foreach (Control control in root.Controls)
    {
        Control foundControl = FindControlRecursive(control, id);
        if (foundControl != null)
            return foundControl;
    }

    return null;
}

//Usage:
Dashboard dashboard = Dashboard.GetInstance();
CormantRadDock dock = (CormantRadDock)dashboard.FindControlRecursive(dashboard, dockID);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T19:32:05+00:00Added an answer on June 3, 2026 at 7:32 pm

    I don’t think you should be afraid of using a recursive FindControl() method at all. Unless the page goes countless levels deep (which it shouldn’t), a recursive function should be able to traverse your control hierarchy without breaking a sweat.

    In short, build a recursive FindControl() method. You have nothing to worry about; just don’t make it static.

    EDIT

    To get a handle on the current page from an outside class, you should be able to do this:

    var page = HttpContext.Current.Handler as Page;
    if (page != null)
    {
        //found the current page
        //...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class which has been steadily growing over time. It's called LayoutManager
I have a class called FooJob() which runs on a WCF windows service. This
I have a class called IssuesView which implements INotifyPropertyChanged . This class holds an
i have this class called MemoryManager, it is supposed to implement a simple smart
I have a class called Path for which there are defined about 10 methods,
I have a class called Object which stores some data. I would like to
I have a class called XMLtoXML.java and this is one of it's methods... import
I have a class of buttons called Keys.java which returns a panel of buttons
I have a class called GestorePersonale which holds a list of instances of another
I have a class called RemoteError with a self.fatal method on it. This methods

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.