0
votes

Each Required Field Validator can validate 1 Controller, but let's say I have 3 DropDownLists.

Date of Birth:

-Day- -Month- -Year-

Now I know that I can validate 1 DropDownList by setting the InitialValue, where the first Item in the DropDownList is "Select a Day", which has a Value="".

But I do not want to use 3 validators. (Day is missing, Month is missing, Year is missing)

I wish to use 1 Validator for all 3, means, if I set the day and the month but I don't set the year, I get (Date must be set), same thing If I set the day and the year without the month..etc...

I know that I can do this with a custom validator, but can I do it with 1 Required Field Validator? Because usually Custom validators requires the page to be refreshed (so it can execute server side codes).

2

2 Answers

2
votes

You can use validation summary

 <asp:ValidationSummary ID="ValidationSummary1"
  HeaderText="Date must be set"
    DisplayMode="BulletList"
     EnableClientScript="true"
       runat="server"/>

And remove the ErrorMessage ,InitialValue and Text properties of required field validator of dropdowns. This will give you required output.

0
votes

I don't think you can accomplish this with just one RequiredFieldControl, either you use Custom Validator, or in the code-behind iterate over each control and see that its index it's not zero (assuming that that's the initial value you want to avoid)

Good luck