This is a migrated thread and some comments may be shown as answers.

RadDatePicker and DataTypeCheck validation

1 Answer 330 Views
DatePicker
This is a migrated thread and some comments may be shown as answers.
JenMaryland
Top achievements
Rank 1
JenMaryland asked on 27 Mar 2020, 02:27 PM

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.

 

1 Answer, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 01 Apr 2020, 08:27 AM

Hello Jen,

 

You can achieve this requirement using a Custom Validator:

https://docs.microsoft.com/en-us/dotnet/api/system.web.ui.webcontrols.customvalidator?redirectedfrom=MSDN&view=netframework-4.8

It won't check for empty fields unless you manually enable the following property:

 <asp:CustomValidator ValidateEmptyText="true" />

Next, you can look at the client-side API of the Telerik date picker control to configure your javascript logic:
https://demos.telerik.com/aspnet-ajax/datepicker/client-sideprogramming/client-sideapi/defaultcs.aspx

You can also check the following property which will allow the user to manually fix their error:

        <telerik:RadDatePicker >
            <DateInput EnableSmartParsing="false"></DateInput>
        </telerik:RadDatePicker>
I hope this will prove helpful.

 

Regards,
Eyup
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
Tags
DatePicker
Asked by
JenMaryland
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Share this question
or