Datepicker format input and output

4 posts, 0 answers
  1. Cape
    Cape avatar
    6 posts
    Member since:
    May 2007

    Posted 15 Apr 2014 Link to this post

    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.
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 15 Apr 2014 in reply to Cape Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Cape
    Cape avatar
    6 posts
    Member since:
    May 2007

    Posted 16 Apr 2014 in reply to Shinu Link to this post

    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.
  5. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 17 Apr 2014 in reply to Cape Link to this post

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