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

  • SEARCH
  • Home
  • 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 8791821
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:53:43+00:00 2026-06-13T22:53:43+00:00

I have an asp.net dashboard site that allows a user to load HTML templates

  • 0

I have an asp.net dashboard site that allows a user to load HTML templates from a dropdownlist. There are multiple types of DevExpress components on the page, including the ASPxDockPanel. If a user changes templates I get an error that the dockpanel already exists, I would like to include a recursive function like the one below that checks to see if any ASPxDockPanels are present on the page, and if they are present remove them. This works for only the first dock panel then bombs out. I think this is because an enumerable set of controls cannot be modified while looping through it. How can I loop though the controls and remove the dock panels at runtime?

protected void LoadTableTemplate(string selectedTemplate, int currentMode)
{
   FindAllDockPanels(this);  
}


public void FindAllDockPanels(Control ctrl)
{
    if (ctrl != null)
    {
        foreach (Control control in ctrl.Controls)
        {
            if (control is ASPxDockPanel)
            {
               ctrl.Controls.Remove(control);
               control.Dispose();
            }
            FindAllDockPanels(control);
        }
     }
}
  • 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-13T22:53:44+00:00Added an answer on June 13, 2026 at 10:53 pm

    Use a temporary collection, like so:

    public void FindAllDockPanels(Control ctrl) {
        if (ctrl != null) {
            List<Control> remove = new List<Control>();
            foreach (Control control in ctrl.Controls) {
                if (control is ASPxDockPanel) {
                    remove.Add( control );
                }
            }
            foreach(Control control in remove) {
                control.Controls.Remove( control );
                control.Dispose(); // do you really need to dispose of them?
            }
            FindAllDockPanels(control);
        }
    }
    

    If you find yourself doing this often, it might be worth moving these “DelayedDelete” actions to an extension method, like so:

    public static void DelayedRemove<T>(this IEnumerable<T item> collection, T itemToRemove) {
        // add it to a private static dictionary bound to the `collection` instance.
    }
    public static void DelayedRemoveFinish(this IEnumerable<T item> collection) {
        // empty the private static dictionary in here
    }
    

    then you’d use it like so:

        public void FindAllDockPanels(Control ctrl) {
        if (ctrl != null) {
    
            foreach (Control control in ctrl.Controls) {
                if (control is ASPxDockPanel) control.Controls.DelayedRemove( control );
            }
            control.Controls.DelayedRemoveFinish();
    
            FindAllDockPanels(control);
        }
    }
    

    Much cleaner, no? 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm developing a dashboard using ASP.NET MVC3 and need to have two divs which
I have ASP.Net code generating my button's HTML for me using divs to get
I have asp.net application that use forms authentication to control access. Let's imagine we
I Have Asp.Net Project, I Cant Use Well from Mappath method. when i using
i have asp.net page that is opened inside an iframe. How to redirect to
I have a web project in asp.net in which i have dashboard on which
I am building a Dashboard app in asp.net. I have placed 3 input buttons
I have an asp.net mvc application where i want the user to be able
I have asp.net(c#) web form with html input text(first name) how i can check
I have ASP.NET site. At one point postback is triggered and some data is

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.