Question

I am adding some controls in my page while loading page.

Some of them are required, so I add requiredfieldvalidator control with them also.

But when I do postback using button click, at that time this dynamically added controls are not validated.

I am not able to understand what is wrong.

protected override void OnPreRender(EventArgs e) {
 Panel pn = new Panel();
RadTextBox rdts = new RadTextBox {
                           ID = "txt" + txField.ColumnName,
                           Width = 200
                        };

                        pn.Controls.Add(rdts);

RequiredFieldValidator rfv = new RequiredFieldValidator {
                        ControlToValidate = "txt" + txField.ColumnName,
                        Display = ValidatorDisplay.Dynamic,
                        Text = "*",
                        ValidationGroup = "standard",
                        ID = "val" + txField.ColumnName,
                        Visible = true
                     };

                     pn.Controls.Add(rfv);
additionalDataPanel.Controls.Add(pn);
}

protected void ClickOK(object sender, EventArgs e) {
     if (Page.IsValid){
         return true;
     }
     else{
         return false;
     }
}
Was it helpful?

Solution

delete

ValidationGroup = "standard" 

from RequiredFieldValidator or add to text box

ValidationGroup = "standard"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top