Iterating through the ControlCollection from CreateUserWizardStep

I am trying to iterate through a ControlCollection on the CreatedUser event of my CreateUserWizardStep. I have a ContentTemplate that contains a table with full checkboxes that I use to collect a user's availability for a week. For brevity, I'll paste my code on pastebin.

Here is the 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 get to the checkboxes inside this second table? What I want to do is find the checked property and thereby build rows that I can put into my database. Any guidance is appreciated.

Thanks!

0


a source to share


1 answer


You will have to recursively go through the controls. But you can also just refer to them via the id you set.

A recursive solution would look something like this:



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) {
      foreach (var c2 in FindControls<T>(c)) yield return c2;
   }
}

      

+2


a source







All Articles