RadDatePicker date validation and preventing auto postback

2 posts, 0 answers
  1. Ashish
    Ashish avatar
    4 posts
    Member since:
    Nov 2016

    Posted 21 Mar Link to this post

    Hi,

    I have a RadDatePicker with AutoPostBack="true". I need this post back to perform some logic and fetch some value for other controls.

    I have having issue with date validation of this control. I have RequiredFieldValidator which check this date field. Now if I make date textbox as empty it fires the validation but also performs a post back which causes issues. How can I check for blank and invalid date in my  RadDatePicker on client side and post back only when it has valid values?

     

    <telerik:RadDatePicker ID="rdpStartDate" runat="server" EnableEmbeddedSkins="true" Skin="Bootstrap"  RenderMode="Lightweight" OnSelectedDateChanged="rdpStartDate_SelectedDateChanged" AutoPostBack="true" 
                            Calendar-Font-Size="Small" Calendar-CalendarTableStyle-Font-Size="Small" Calendar-DayStyle-Font-Size="Small" Calendar-TitleStyle-Font-Size="Small" />

    <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidatorStartDate" ControlToValidate="rdpStartDate" Display="Dynamic" ErrorMessage="Start Date is invalid." CssClass ="controlValidationLabels"> </asp:RequiredFieldValidator>

  2. Ashish
    Ashish avatar
    4 posts
    Member since:
    Nov 2016

    Posted 21 Mar Link to this post

    I also have another similar datepicker for enddate. I wrote below javascript function and called it on ClientEvents-OnDateSelected event of both my datepickers. This seem to work but I want to know if there is another cleaner way of doing it.
    I want to know why get_selectedDate().format("yyyy/MM/dd") stops autopostback for a blank date? Execution reaches return statement only when both my dates are not blanks.




    function ValidateDates(sender, args) {
                debugger
                
                var datePickerStartDate = $find("<%=rdpStartDate.ClientID %>");
                var datePickerEndDate = $find("<%=rdpEndDate.ClientID %>");

                var selectedStartDate = datePickerStartDate.get_selectedDate().format("yyyy/MM/dd");
                var selectedEndDate = datePickerEndDate.get_selectedDate().format("yyyy/MM/dd");
                return;
                

            }
Back to Top