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

Datepicker format input and output

3 Answers 132 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
Cape
Top achievements
Rank 1
Cape asked on 15 Apr 2014, 08:00 AM
We using the datepicker with input format "dd-mm-yyyy" in our asp.net web application. Created an validator function for this format. Works fine when leaving the input field it checks the format "dd-mm-yyyy" but when we want to save the record our validator function gets the date as "yyyy-mm-dd" which is invalid according to our validator function. What to do.

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 1
answered on 16 Apr 2014, 04:32 AM
Hi Cape,

Please have a look into the sample code snippet which works fine at my end. Please provide your code if it doesn't help.

ASPX:
<telerik:RadDatePicker ID="RadDatePicker1" runat="server" DateInput-DateInput-DisplayDateFormat="dd-MM-yyyy" DateInput-DateFormat="dd-MM-yyyy">
</telerik:RadDatePicker>
<telerik:RadButton ID="RadButton1" runat="server" Text="Save" OnClick="RadButton1_Click">
</telerik:RadButton>

C#:
protected void RadButton1_Click(object sender, EventArgs e)
{
    //date is getting in the format dd-MM-yyyy
    DateTime date = Convert.ToDateTime(RadDatePicker1.SelectedDate);
}

Thanks,
Shinu.
0
Cape
Top achievements
Rank 1
answered on 16 Apr 2014, 10:39 AM
My problem is that i have a customvalidor that gets the value of my date field.

In my validator i use getElemetById("id").value to get the value of my datepicker.  The value is in format "yyyy-mm-dd" when pressing ok on my form. When i use the datepicker and select a date the value of my datefield is still in the format of "yyyy-mm-dd" in the validator but pressing  ok the value in my customvalidator is "dd-mm-yyyy" and my validator fails.
0
Shinu
Top achievements
Rank 1
answered on 17 Apr 2014, 06:38 AM
Hi Cape,

Please have a look into the sample code snippet which works fine at my end. Please provide your full code if it doesn't help.

ASPX:
<telerik:RadDatePicker ID="raddateDateFormat" runat="server" DateInput-DateInput-DisplayDateFormat="dd-MM-yyyy" DateInput-DateFormat="dd-MM-yyyy">
</telerik:RadDatePicker>
<asp:CustomValidator ID="cvDateFormat" runat="server" ValidationGroup="Group1" ClientValidationFunction="Validate" EnableClientScript="true" ValidateEmptyText="true">
</asp:CustomValidator>
<telerik:RadButton ID="radbtnValidateDate" runat="server" Text="ok" ValidationGroup="Group1"
    AutoPostBack="false">
</telerik:RadButton>

JavaScript:
<script type="text/javascript">
    function Validate() {
        var datepicker = $find("<%=RadDatePicker1.ClientID %>");
        alert(datepicker.get_dateInput().get_value());
        //your code for validation
    }
</script>

Thanks,
Shinu.
Tags
Calendar
Asked by
Cape
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 1
Cape
Top achievements
Rank 1
Share this question
or