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

How to disable RadDatePicker validation

7 Answers 598 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
Vlad
Top achievements
Rank 1
Vlad asked on 04 Oct 2011, 10:01 AM
Hi.

I am using RadDatePicker in connection with asp:RequiredFieldValidator and I encountered some strange behaviour.
This is my aspx file:
<telerik:RadDatePicker ID="dpVeljaOd" AutoPostBack="false" CausesValidation="false" runat="server">
   <DateInput CausesValidation="false" runat="server"></DateInput>
   <DatePopupButton Enabled="true" runat="server" />
 </telerik:RadDatePicker>
 <asp:RequiredFieldValidator ID="valrqVeljaOd" CssClass="errorText" ErrorMessage="Obvezno polje" ControlToValidate="dpVeljaOd" Enabled="true" runat="server"></asp:RequiredFieldValidator>

The strange behaviour:
If you type or select a valid date, delete it and move away from input field (i.e. click in some other field), then validation is triggered. Validator is static and not dynamic, it is executed on server side and there is no postback detected (postback is disabled anyway).
Validation is not triggered, if you have entered and later deleted invalid date. It is also not triggered, if you haven't enter a date at all.
Same thing happens in Telerik validation demo .

How can I get rid of this annoying behaviour?

7 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 04 Oct 2011, 10:47 AM
Hello Vlad,

You can attach the client event OnError and handle the error there. Here is a sample code to achieve the same.
<telerik:RadDatePicker ID="RadDatePicker1" runat="server" Width="150px" AutoPostBack="false">
    <DateInput DateFormat="dd MMM yyyy" ClientEvents-OnError="ShowMessage">
    </DateInput>
</telerik:RadDatePicker>
<asp:Label ID="Label1" runat="server" Text=""></asp:Label>
JS:
function ShowMessage()
 {
    document.getElementById("Label1").innerText="InvalidDate!!";
 }

Thanks,
Princy.
0
Vlad
Top achievements
Rank 1
answered on 04 Oct 2011, 11:05 AM
Hi Princy,

If I understood correctly, the example you have given shows how to display a validation message via Javascript and client event OnError. However, I would like to know is how to prevent RadDatePicker to fire validation despite CausesValidation and AutoPostback properties being set to false and validator being static. I am a weird person and want my validations to happen on button click.

Hence the problem is not in displaying the message, but rather in me not wanting to display the message on datePicker blur.
0
Accepted
Vasil
Telerik team
answered on 06 Oct 2011, 10:22 AM
Hi Vlad,

You will get the same behavior with asp:TextBox. Even when CausesValidation is "false".
<asp:TextBox runat="server" ID="TextBox1"></asp:TextBox>
<asp:RequiredFieldValidator runat="server" Text="Required" ControlToValidate="TextBox1"></asp:RequiredFieldValidator>
1) Type some text in the textbox
2) Blur the textbox
3) Focus the textbox and delete the text
4) Blur the textbox again and you will see that the validation is fired for the control.

Greetings,
Vasil
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
Peter Livsey
Top achievements
Rank 1
answered on 10 Oct 2011, 10:20 AM
Hi, I'm trying to stop the default validation firing too by setting the CausesValidation property to false, but it still seems to fire the validation event.

Have you managed to achieve this?

Peter
0
Vasil
Telerik team
answered on 10 Oct 2011, 01:58 PM
Hello Peter,

This is more general question and not a particular problem with the RadInput. This is the way that the Asp:Validators are working.
Indeed the CausesValidation property is made to work only with AutoPostBack is set to true for the inputs. This property determinate whether validation should perform before the PostBack or not.
The property does not change the way that Validators show their messages after changing text and blur the controls. You could set Page_ValidationActive to false to disable validation of the page in some circumstances. See the resources below for more information:
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.textbox.causesvalidation.aspx
http://msdn.microsoft.com/en-us/library/aa479045.aspx

Regards,
Vasil
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
Peter Livsey
Top achievements
Rank 1
answered on 10 Oct 2011, 02:49 PM
It's not so much that I don't want to fire the validation but the default styling of changing the input box border colour and displaying the 'warning' icnon in the input box clashes with the styling that we use across our applications, so I was trying to see how I could stop those changes happening on a validation error.
0
Vasil
Telerik team
answered on 10 Oct 2011, 04:26 PM
Hi Peter,

If you refer to the 'error' styles, for example when you enter letters inside the NumericTextBox, then check this help topics about styling the inputs.
http://www.telerik.com/help/aspnet-ajax/input-styles.html
http://www.telerik.com/help/aspnet-ajax/input-html-output-css-styling.html
You could use your own style when the input has invalid value.

Greetings,
Vasil
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Tags
Calendar
Asked by
Vlad
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Vlad
Top achievements
Rank 1
Vasil
Telerik team
Peter Livsey
Top achievements
Rank 1
Share this question
or