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;
}
Go to the complete details ...