Wrox Programmer Forums
|
ASP.NET 1.x and 2.0 Application Design Application design with ASP.NET 1.0, 1.1, and 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.x and 2.0 Application Design section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 4th, 2003, 01:10 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default Looping through Controls on a Page

Hello all,

   I am trying to loop through a page that has multiple controls, then I want to do something if a particular control type is found. The problem I am having is that I do a Me.Controls.Count, and it gives me a count of 3 when it should be like 15. Is my syntax incorrect? Thanks

Jim

 
Old December 4th, 2003, 02:57 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

When you look thru the controls collection of the page, you will almost always get 3 controls. Here are those controls:
1. All the literal text before the <form> tag,
2. The <form> tag
3. All the literal text after the <form> tag (</form>)

All the controls that fall between the <form> and </form> tags are contained within the form control and can be found in its controls collection. The same applies for any control that lives within another controls, such as controls in an asp:placeholder.

You will need to write a recursive function that digs down into each child control. Simply test for more controls within the control that is being handled and keep going until you reach a controls collection that is empty. You could pass a control or a controls collection into the function, doesn't matter which.

If you need help with this recursive function, post back and we can help some more.

Peter
------------------------------------------------------
Work smarter, not harder.
 
Old December 4th, 2003, 03:20 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

Thanks, that makes sense after looking at some values while debugging. I just thougt that maybe there was a form collection and I could do something like

Me.Form.cbxxx

then do something ...









Similar Threads
Thread Thread Starter Forum Replies Last Post
Looping thru Form values posted to a page.. kingroon ASP.NET 2.0 Basics 1 February 13th, 2008 02:07 PM
accessing page controls into another page labelle ASP.NET 2.0 Basics 0 January 11th, 2007 09:53 AM
Looping controls and array redim mega Excel VBA 2 April 19th, 2005 11:57 AM
Looping Form Generation - Refering to Controls IP076 Pro PHP 1 December 10th, 2004 08:13 PM
Looping Through Controls stu9820 ASP.NET 1.0 and 1.1 Professional 2 March 4th, 2004 01:40 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.