Solved

Collections in asp.net

Posted on 2009-07-14
5
258 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
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…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

622 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