Solved

Collections in asp.net

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Server Error 11 58
Need to start a web service from Visual Studio 2015 Pro 2 24
SQL Help 27 45
VB.Net/LINQ: ".Contains" condition not finding existing result in MSSQL 16 36
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…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

777 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