Link to home
Start Free TrialLog in
Avatar of Tom Knowlton
Tom KnowltonFlag for United States of America

asked on

Loop through all controls in a user control

How do I properly recurse all of the controls in a User Control (.ascx)?

here is my attempt:

  private Control FindNestedControl(ControlCollection c, string typeasstring, bool value)
        {
            Control tempControl = null;

            foreach (Control cc in c)
            {
                string contype = cc.GetType().ToString();
                if (contype == typeasstring)
                {
                    ((System.Web.UI.WebControls.TextBox)cc).BorderWidth = 0;
                    ((System.Web.UI.WebControls.TextBox)cc).ReadOnly = value;
                    ((System.Web.UI.WebControls.TextBox)cc).Enabled = !value;
                    tempControl = FindNestedControl(cc.Controls, typeasstring, value);
                }
            }

            return tempControl;
            
        }

Open in new window





My intent is to loop through all the controls and make the textbox controls read only.
SOLUTION
Avatar of Easwaran Paramasivam
Easwaran Paramasivam
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Tom Knowlton

ASKER

thx