Solved

Collections in asp.net

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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

Suggested Solutions

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…

830 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