How to disable RadDatePicker validation

8 posts, 1 answers
  1. Vlad
    Vlad avatar
    19 posts
    Member since:
    Aug 2012

    Posted 04 Oct 2011 Link to this post

    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?
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 04 Oct 2011 Link to this post

    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.
  3. Vlad
    Vlad avatar
    19 posts
    Member since:
    Aug 2012

    Posted 04 Oct 2011 Link to this post

    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.
  4. Answer
    Vasil
    Admin
    Vasil avatar
    1638 posts

    Posted 06 Oct 2011 Link to this post

    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
  5. Peter Livsey
    Peter Livsey avatar
    44 posts
    Member since:
    Aug 2012

    Posted 10 Oct 2011 Link to this post

    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
  6. Vasil
    Admin
    Vasil avatar
    1638 posts

    Posted 10 Oct 2011 Link to this post

    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
  7. Peter Livsey
    Peter Livsey avatar
    44 posts
    Member since:
    Aug 2012

    Posted 10 Oct 2011 Link to this post

    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.
  8. Vasil
    Admin
    Vasil avatar
    1638 posts

    Posted 10 Oct 2011 Link to this post

    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
Back to Top