I'm trying to get the RadDatePicker to work with the CompareValidator with the DataTypeCheck operator. Initially, I wanted to use this as a dynamically created control in the code-behind. (It works great with a normal validator, but it also validates blank textboxes when I don't want it to). I noticed this seemed to be an issue 10 years ago from what I've searched, but is this still the case?
I did a little testing here -
<form id="form1" runat="server"> <div> <telerik:RadScriptManager ID="RadScriptManager1" runat="server"> </telerik:RadScriptManager> <asp:Label ID="lblDate" Text="Date:" AssociatedControlID="txtDate" runat="server" /> <asp:TextBox ID="txtDate" runat="server" /> <asp:CompareValidator ID="txtDatecompare" Text="(Invalid Date)" ControlToValidate="txtDate" Type="Date" Operator="DataTypeCheck" runat="server" /> <hr /> <asp:Label ID="lblTelerikDate" Text="Date:" AssociatedControlID="rdDate" runat="server" /> <telerik:RadDatePicker ID="rdDate" runat="server"> </telerik:RadDatePicker> <asp:CompareValidator ID="txtRadDateCompare" Text="(Invalid Date)" ControlToValidate="rdDate" Type="Date" Operator="DataTypeCheck" runat="server" /> <br /> <asp:Button ID="btnSubmit" Text="Submit" runat="server" /> </div></form>
The submit button simply returns the time of day. What I expected to happen is -
Textbox is left blank - Do nothing. I would expect this, and handle required field validators late in the code.
Textbox has a valid date - Do nothing.
Textbox has an invalid date - Display a message and cancel the postback. However, the above code still causes a postback. If I put an invalid date into the normal textbox, it works fine. If I put an invalid date into the raddatepicker, the submit button still fires. My goal is to do this dynamically, so if it's not possible, I could always create a server-side validation to loop through the added controls.
