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

RadDatePicker date validation and preventing auto postback

1 Answer 368 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
Ashish
Top achievements
Rank 1
Ashish asked on 22 Mar 2017, 04:20 AM

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>

1 Answer, 1 is accepted

Sort by
0
Ashish
Top achievements
Rank 1
answered on 22 Mar 2017, 04:57 AM
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;
            

        }
Tags
Calendar
Asked by
Ashish
Top achievements
Rank 1
Answers by
Ashish
Top achievements
Rank 1
Share this question
or