0

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).

user1665700
  • 512
  • 2
  • 13
  • 28

2 Answers2

2

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.

syed mohsin
  • 2,948
  • 2
  • 23
  • 47
  • This solution worked, BUT, the summary is showing the results of all other validators, I want this summary to be specified to only these 3 validators, how can I accomplish that? – user1665700 Dec 16 '12 at 14:14
  • use validation group on validation summary, req validators and on the button. – syed mohsin Dec 16 '12 at 14:21
  • 1 button should be hidden and it will fire through Javascript when your submit button is fired. see this http://stackoverflow.com/questions/7646162/how-to-fire-button-click-event-from-javascript-in-asp-net – syed mohsin Dec 16 '12 at 14:44
0

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

Felipe Gavilán
  • 393
  • 2
  • 10