views:

300

answers:

1

Hello,

I am attempting to iterate through a ControlCollection in the CreatedUser event of my CreateUserWizardStep. I have a ContentTemplate that contains a table full of checkboxes that I am using to gather a user's availability during the week. For the sake of brevity I will paste my code on pastebin.

Here is a link to the .aspx page. Here is the CreatedUser event.

This loop:

foreach (Control c in CreateUserWizardStep1.ContentTemplateContainer.Controls)
    {
        if (c.GetType() == typeof(CheckBox))
        {
        }
    }

Gives me a WizardDefaultInnerTable instead of...well something easier to work with.

How do I go about getting at the checkboxes inside that second table? What I want to do is find the checked property and with that, build strings that I can put into my database. Any guidance is appreciated.

Thanks!

+1  A: 

You'd have to recursively go through the controls. But, you could also just reference them through the id's you set.

The recursive solution would look something like:

IEnumerable<T> FindControls<T>(Control parent) where T : Control {
   T t = parent as T;
   if (t != null) yield return t;

   foreach (Control c in parent.Controls) {
      return FindControls<T>(c);
   }
}
Mark Brackett
Mark, I couldn't get your function to work. However, it lead me down the right path! A google search for recursively iterating through container controls gave me [this](http://www.codeproject.com/KB/cs/Generic_Iterator.aspx) page. I modified it slightly to suit my needs.Thanks!
ChristopherWright