473,402 Members | 2,050 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

How to loop for controls, in multi user controls?

10
I want to ask if I can loop in my controls, like textbox, dropdown list or etc, in which they are in a page's user control. The scenario is that, assume I have a page called 'Page.aspx' and I have 3 user controls in that page(uc1, uc2 and uc3) and an asp panel (named PnlTab1) to contain all these controls in each user control. I am using that code to reach my controls:

------------
Expand|Select|Wrap|Line Numbers
  1. UserControl uc1, uc2, uc3;             
  2. uc1 = usercontrol1;             
  3. uc2 = usercontrol2;             
  4. uc3 = usercontrol3;              
  5.  
  6. foreach (Control c in uc1.FindControl("PnlTab1").Controls)             
  7. {                 
  8.    if (c is TextBox)                     
  9.    ((TextBox)c).Enabled = true;             
  10. }              
  11. foreach (Control c in uc2.FindControl("PnlTab1").Controls)             
  12. {                 
  13.    if (c is TextBox)                     
  14.    ((TextBox)c).Enabled = true;             
  15. }             
  16. foreach (Control c in uc3.FindControl("PnlTab1").Controls)             
  17. {                 
  18.    if (c is TextBox)                     
  19.    ((TextBox)c).Enabled = true;             
------------------------
Now, I do not want to write each time 'foreach (Control c in uc3.FindControl("PnlTab1").Controls' . Can I recursively do that?

Thank you all a lot!
Jul 24 '11 #1
2 2145
Frinavale
9,735 Expert Mod 8TB
Have you considered writing a Public method that disables all of the TextBoxes in the user controls themselves?

That way you don't need to loop through controls like you are doing (expensive because the majority of them aren't what you're going to be looking for).

You'd just call the "DisableTextBoxes" method of the user control.

Or you could even implement Public Properties in the user controls to accomplish the same thing.

-Frinny
Jul 27 '11 #2
dyte
10
No I did not, beside this, I have done that and the problem is solved;
----------------------
Expand|Select|Wrap|Line Numbers
  1. UserControl[] ucs = new UserControl[3] = {uc1, uc2, uc3);
  2. foreach(UserControl uc in ucs)
  3. {
  4.     foreachforeach (Control c in uc.FindControl("PnlTab1").Controls)             
  5.     {                 
  6.        if (c is TextBox)                     
  7.        ((TextBox)c).Enabled = true;             
  8.     } 
  9. }
-----------------------

Thank you anyway... I hope this helps, who need this.
Jul 28 '11 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: BBM | last post by:
Hi, I have been developing with C# User Controls and occasionally have a problem where I "lose" a control from the design surface of the User Control. The controls that I am using to build my...
0
by: Verane | last post by:
Hi all, I want to define a user control (called BaseUserControl) in one assembly, and define another user control (called derivedUserControl) in another assembly which derived from...
6
by: trinitypete | last post by:
I have a user control that is basically a login dialogue. If I add the user control to webpage1, can I access the properties directly from C# codebehind, or do I have to access the properties from...
4
by: Michael | last post by:
Thank you for any help you can provide. This is what I have: index.aspx - contains nothing but a form with runat = server header.ascx - contains asp image box welcome.ascx - contains text...
1
by: Jim Corey | last post by:
Hello, I have common dropdowns on several user controls, and so I'm trying to get of repetitive code. The dropdowns allow me to pick months, days, etc. I've put a dropdown on a usercontrol...
2
by: Michael Ramey | last post by:
Howdy, I think I have a good question! I'm creating a usercontrol, and within this usercontrol, I'm dynamically creating controls (imagebuttons to be exact), that the user can click on which...
5
by: Gopal Krish | last post by:
Wondering what's the pros and cons in creating reusable web controls using 1. User Controls 2. C# class that creates the controls programmatically Example, I want to develop a page menu...
1
by: Aquila Deus | last post by:
Hi all! Following is the method I use to insert child controls into user controls, so that you may use them just like ordinary custom controls: ...
1
by: Josh | last post by:
I am trying to move some of my more common controls into user controls. However, I seem to have problems maintaining state of databound controls that are contained within user controls. On...
1
by: Demetri | last post by:
I'm trying to determine if we want to use panels or user controls for our pages. Our primary concern is performance, page loading and posting speed. To illustrate my question, lets use the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.