I'm creating several textboxes and dropdown controls. Some have a related RequiredFieldValidator control. The RequiredFieldValidator is created as follows:
RequiredFieldValidator getValidator(string ctrlNo, bool visible, Label lbl, TextBox txt, RadComboBox rcb)
{
string lblName = (lbl==null ? "This " : lbl.Text.Replace(" "," "));
RequiredFieldValidator rfv = new RequiredFieldValidator();
rfv.ID = "rfv_" + ctrlNo;
rfv.Visible = visible;
if (txt.Visible == true)
rfv.ControlToValidate = txt.ID;
if (rcb.Visible == true)
rfv.ControlToValidate = rcb.ID;
rfv.ErrorMessage = lblName;
rfv.ToolTip = lblName;
rfv.Text = "*";
rfv.ValidationGroup = "cmsave";
return rfv;
}
This method is called from the following section of code which inserts rows into a table. Insert location is marked with a PlaceHolder control (ID="tblInsertRow").
// instantiate each control.
Label lbl = getLabel(ctrlNo, bShowLbl, property.Label);
TextBox txt = getTextBox(ctrlNo, bShowTxt, property.ControlWidth);
RadComboBox rcb = getComboBox(ctrlNo, bShowRcb, property.ControlWidth, list);
RequiredFieldValidator rfv = getValidator(ctrlNo, bShowRfv, lbl, txt, rcb);
// STEP 2 - ADD CONTROLS TO A ROW
if (txt.Visible == true || rcb.Visible == true)
{
// create new table row.
TableRow row = new TableRow();
// create 1st cell; add label; add cell to row.
TableCell cell_0 = new TableCell();
if (lbl.Visible == true)
cell_0.Controls.Add(lbl);
cell_0.ColumnSpan = 1;
row.Controls.Add(cell_0);
// create 2nd cell; add control; add cell to row.
TableCell cell_1 = new TableCell();
if (txt.Visible == true)
cell_1.Controls.Add(txt);
if (rcb.Visible == true)
cell_1.Controls.Add(rcb);
if (rfv.Visible == true)
cell_1.Controls.Add(rfv);
cell_1.ColumnSpan = 3;
row.Controls.Add(cell_1);
// add row at place holder into existing table.
tblInsertRow.Controls.Add(row);
}
When the user clicks the "Save" button, I force a validation of all validators as follows:
// force validation of controls.
Page.Validate("cmsave");
if (Page.IsValid == false)
{
// display message.
return;
}
The problem I'm having is that Page.IsValid is always "true". I read some older posting that stated that you cannot use RequiredFieldValidator with AJAX, but I don't believe that's true anymore since I've done it before with static controls. This is the 1st time I'm trying to do this with controls created at runtime. These controls are created in a User Control that is displayed on a Page with a Master Page. Could this be a RadScriptManager related issue? What am I missing? TIA, Gary.