Button to load radDateInput control in mm/dd/yyyy HH:mm format

2 posts, 0 answers
  1. Steve LaForge
    Steve LaForge avatar
    61 posts
    Member since:
    Feb 2005

    Posted 11 Feb 2011 Link to this post

    I have a date input where a user can choose to enter a date and time, or they can click on a button to load the current date and time.  I would prefer to set the value with client-side code if they click the button, but I cannot get it to work.  It will enter the current date, but not the time.  My control looks like:

    <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
        <script language="javascript" type="text/javascript">
          function setDateTimeAcknowledged() {
            var toDay = new Date();
            alert("toDay = " + toDay);
            var dateInput = $find("<%= dateAcknowledged.ClientID %>");
            dateInput.set_selectedDate(toDay);
          }
          function setEstReturnDate() {
            var toDay = new Date();
            var dateInput = $find("<%= dateEstimatedReturn.ClientID %>");
            dateInput.set_selectedDate(toDay);
          }
        </script>
    </telerik:RadCodeBlock>
    ...
    <telerik:RadDateInput ID="dateAcknowledged" runat="server" DisplayDateFormat="MM/dd/yyyy HH:mm" Width="125" CssClass="NotRequired" />
    <telerik:RadToolTip ID="tipDateAcknowledge" runat="server" HideEvent="LeaveTargetAndToolTip" TargetControlID="dateAcknowledged" 
        Position="BottomRight" RelativeTo="Element" ShowEvent="OnMouseOver" 
        Text="mm/dd/yyyy HH:mm (24HR) format less than or equal to today's date" />
    <asp:Button ID="btnAckNow" runat="server" Text="Now" CausesValidation="false" 
        OnClientClick="setDateTimeAcknowledged(); return false;" />

    If I click on the button, the results will have the right date but not the time.  For example, if I run it right now I get "02/11/2011 00:00" inserted in the raddateinput field, while the alert shows "toDay = Fri Feb 11 15:56:36 CST 2011".

    If I remove the OnClientClick parameter from the button, it will execute the server-side code that I have coded for the button.  It looks like:

    Protected Sub btnAckNow_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAckNow.Click
        dateAcknowledged.SelectedDate = Date.Now
      End Sub

    The results are now '02/11/2011 15:57".

    How do I need to code the client-side code so that it properly loads both the date and the time in the control?

    Thank you!


  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 14 Feb 2011 Link to this post

    Hello Steve,

    You can easily achieve this by setting RadDateInput's DateFormat property to the appropriate Format Character. Here is the sample aspx.
    aspx:
    <telerik:RadDateInput DateFormat="f" ID="dateAcknowledged" runat="server" DisplayDateFormat="MM/dd/yyyy HH:mm"
           Width="125" />

    You can find more information on Formatting Dates from the following documentation
    Formatting Dates

    Thanks,
    Shinu.
Back to Top