Sure, in Page_Load:
if (ConditionsMet)
{
RequiredFieldValidator val = new RequiredFieldValidator();
val.ControlToValidate = "idOfOtherControl";
val.Text = "* Required";
val.ErrorMessage = "You must provide a value for my other control";
somePlaceHolderInYourPage.Controls.Add(val);
}
So this assumes you have some <asp:PlaceHolder> or other control positioned
in the page where you want to add in your validation control.
-Brock
DevelopMentor
http://staff.develop.com/ballen Is there a way to, based on the selection of another control, add a
required field validator to another field (code behind vb.net)? I
don't want the field to be required unless a checkbox or date field
has been entered.
Thanx.