Solved

Collections in asp.net

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

747 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now