Solved

Collections in asp.net

Posted on 2009-07-14
5
257 Views
Last Modified: 2013-11-26
I would like to make certain objects on the screen invisible on startup. I easily have a few hundred objects. Can I scroll through a collection of objects in my screen and set the properties of those that meet a naming criteria to be invisible?  (asp.net)

thanks
0
Comment
Question by:adimit
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 21

Assisted Solution

by:Craig Wagner
Craig Wagner earned 60 total points
ID: 24851829
Yes. You'll need to use recursion because any given control can contain other controls.
protected void Page_Load( object sender, EventArgs e )
{
    HideControls( this.Controls );
}
 
public void HideControls( ControlCollection controls )
{
    foreach( Control control in controls )
    {
        if( control.HasControls() )
        {
            Initialize( control.Controls );
        }
 
        if( control.ID == "whatever" )
        {
            control.Visible = false;
        }
    }
}

Open in new window

0
 

Accepted Solution

by:
adimit earned 0 total points
ID: 24854134
This is the actual command. The above command does not return the controls on the page
For Each myControl In Me.Form.Controls
                                    myControl.imageurl = formula.BottomImage
 Next
0
 
LVL 21

Expert Comment

by:Craig Wagner
ID: 24855310
Actually, the code I posted does return all the controls on the page. I know because I'm using it in an existing application.

The loop that was posted in the author's comment only returns the controls that are direct children of the page. If a control is inside another control (e.g. a panel) then the author's comment will not work correctly. Also, the author asked about hiding controls on a page, and setting the ImageUrl property does not do that.

I see that this user has a history of accepting his own solutions after other have stepped in to help. I will keep that in mind in the future.
0
 

Author Comment

by:adimit
ID: 24858260
with all due respect to craig, I accept over 90% of all solutions given to me because well over 90% of the solutions that people provide actually work. In all cases I actually assign points to the contributors.

I tested multiple methods prior to posting the question. CraigWarner's solution returned a collection of 5 items , and it is a solution that i tried prior to posting my question. My solution returns all 1500 objects that I have on the screen. Hence my solution is more complete. I am more then happy to give Craig points for his attempt. I was merely posting my solution so that it may help others with the same problem.  
0

Featured Post

Is Your DevOps Pipeline Leaking?

Is your CI/CD pipeline a hodge-podge of randomly connected tools? You’ve likely got a tool to fix one problem & then a different tool to fix another, resulting in a cluster of tools with overlapping functionality. Learn how to optimize your pipeline with Gartner's recommendations

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question