Preventing submit click if Date entered is invalid.

7 posts, 1 answers
  1. Shubh
    Shubh avatar
    5 posts
    Member since:
    May 2014

    Posted 26 May 2014 Link to this post

    How do we prevent submit button click, if user has selected invalid date.

    Currently, I am able to display the error message. But even if the error message is there and user clicks on Submit/Save  I am still able to submit form with invalid date.

    While searching in Google, I found one suggestion to achieve this is adding RequiredFieldValidator on page. But this would turn make that field mandatory, which I cannot do.

    Thanks.
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 26 May 2014 in reply to Shubh Link to this post

    Hi Shubh,

    One suggestion is that based on the condition you can enable/disable the Save Button. Please have a look into the JavaScript which checks the condition like if the selected date is greater than 15 then it will enable the button otherwise it will disable the button.

    JavaScript:
    function ValidateDate(sender, args) {
        var button = $find("<%=RadButton1.ClientID %>");
        var selectDate = new Date(args.get_newDate());
        if (selectDate.getDate() > 15)
            button.set_enabled(true);
        else
            button.set_enabled(false);
    }

    Please let me know if you have any concern.
    Thanks ,
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Shubh
    Shubh avatar
    5 posts
    Member since:
    May 2014

    Posted 27 May 2014 in reply to Princy Link to this post

    Hey Princy,

    Thanks for you suggestion. Will implement it.

    Before that, is Calendar control build like that? In case of invalid date also it will allow the page to submit?

    If Yes, then how do I maintain the error message?

    Thanks.
  5. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 27 May 2014 in reply to Shubh Link to this post

    Hi Shubh,

    The OnError client-side event is fired when one tries to set invalid value for the DateInput. You can handle the InvalidDate in OnError event and prevent the Button Click and validate the form. 

    Thanks,
    Princy.
  6. Shubh
    Shubh avatar
    5 posts
    Member since:
    May 2014

    Posted 27 May 2014 in reply to Princy Link to this post

    Let me try that. Thanks.
  7. Shubh
    Shubh avatar
    5 posts
    Member since:
    May 2014

    Posted 27 May 2014 in reply to Princy Link to this post

    I have my code as below:

    <telerik:RadDatePicker ID="rdpDob" runat="server" AutoPostBack="true"   DateInput-EmptyMessage="MaxDate" MinDate="01/01/1000"MaxDate="01/01/3000">

    I am validating in my Server Side. Now, when I enter invalid data in my date field, I don't get the entered invalid values. 

    rdpDob.SelectedDate

    This return's  null.

    Any idea what I am missing?

    Thanks,
  8. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 27 May 2014 in reply to Shubh Link to this post

    Hi Shubh,

    The current implementation of RadDatePicker/RadDateTimePicker there is no way of posting back invalid Date to server. This is due to the reason that picker control tries to parse value posted from client to DateTime and this might break the control. If the value is not valid DateTime on postback it will be cleared. On server side you can actually access the invalid value via InvalidTextBoxValue property of the picker as follows.

    C#:
    string invalidDate=RadDatePicker1.DateInput.InvalidTextBoxValue;

    Thanks,
    Princy.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017