Dynamically Adding ASP.NET Validation Controls
<p>Having a little bit of trouble, that I've been trying to figure out for a few hours now.</p>

<p>I have three panels, two of which are visible=false at any given time. Two of the three panels have text boxes that require validation of user input.  The code below loops through all the controls in all three panels and creates two validation controls for each text box.</p>

<p>The first panel, Settings, only allows numbers. Both Validations catch errors as intended.</p>

<p>the second panel, ConfigImages, has three textboxes. Two allow text/numbers/Limited symbols and requires an input.  The third Requires an URL. The Validators are not firing on these text boxes.</p>

<p>Any Ideas why these validators aren't firing?</p>

<p>Code-behind</p>

<pre><code>        //Initialize page validation
        foreach (Panel p in this.Form.Controls.OfType&lt;Panel&gt;().ToList())   
        {
            foreach (TextBox ctrl in p.Controls.OfType&lt;TextBox&gt;().ToList())
            {
                //add a new RequiredFieldValidator for each textbox
                this.Form.Controls.Add(new RequiredFieldValidator()
                {
                    //set the properties of the new RequiredFieldValidator
                    ControlToValidate = ctrl.ID.ToString(),
                    Display = ValidatorDisplay.None,
                    Enabled = true,
                    ErrorMessage = ctrl.ID.Substring(3) + " Field cannot be empty"
                }
                );

                //Add a new RegularExpressionValidator for each textbox
                this.Form.Controls.Add(new RegularExpressionValidator()
                {
                    //set the properties of the new RegularExpressionValidator
                    ControlToValidate = ctrl.ID.ToString(),
                    Display = ValidatorDisplay.None,
                    Enabled = true,
                    ErrorMessage = ctrl.ID.Substring(3) + " field has invalid characters",
                    //Double Ternary Allows 0-255 for all Settings textbox , a-zA-Z0-9'!#$%&amp;'*+/=?^_`{|}~.- for Slide Text
                    //or URL for URL textbox
                    ValidationExpression = (ctrl.Parent.ID == "pnlSettings") ? @"^[0-9]*$" :
                        (ctrl.ID == "txtUrl") ? @"http(s)?://([\w-]+\.)+[\w-]+(/[\w- ./?%&amp;=]*)?" :
                        @"^[a-zA-Z0-9#$%&amp;@?""{}[]]*$"
                }
                );
            }
        }
        //Add Validation Summary        
        this.Form.Controls.Add(new ValidationSummary() { ShowMessageBox = true, ShowSummary = false });
</code></pre>
