This is a migrated thread and some comments may be shown as answers.
Button to load radDateInput control in mm/dd/yyyy HH:mm format
1 Answer 21 Views
This is a migrated thread and some comments may be shown as answers.
Steve LaForge
Top achievements
Rank 1
Steve LaForge asked on 11 Feb 2011, 11:00 PM
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!


1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 1
answered on 14 Feb 2011, 09:04 AM
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.
Tags
Input
Asked by
Steve LaForge
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 1
Share this question
or