views:

11

answers:

1

Hello,

I ve two aspCalendar controls on the website. I would like to perform validation (date from Calendar2 should be greater then date from Calendar 1).

<asp:CompareValidator ID="CompareValidator1" runat="server"
    ErrorMessage="CompareValidator" 
    ControlToValidate="Calendar2" 
    Operator="GreaterThanEqual" 
    Type="Date" 
    ControlToCompare="Calendar1"
/>

There are a lot examples of validation but with ControlToValidate as textBox or label, What about more complex Controls, is there any way I can tell which property from that control has to be used?

Maybe Client side validation ? But how to do this ?

Thanks for help

+1  A: 

Hey,

I would recommend using a customvalidator, which gives you complete control over the way the validation occurs. The control to validate may not accept the calendar; however, you can point it to a textbox, but behind the scenes in the servervalidate function validate your calendars, and so that is a workaround to making the validators work with controls like the calendar.

You could use client validation, but it depends on what you are trying to validate and how easy it would be; there is a lot of markup with the calendar control, so that might be hard...

HTH.

Brian
CustomValidator doesnt work on controls which are in detailsView after performin for example update on that detailsView.For example RequiredFiledValidator works with no problem while CustomValidator has problems (Validation doesnt occur):/
gruber
Leave the CustomValidator, and in the DetailsView.ItemUpdating event, call Page.Validate(), and check whether the Page is valid. THen you can cancel the update and return back to that Page.
Brian