2

I am using ajaxToolkit:CalendarExtender with a TextBox and I want users to also be able to input the time component.

Whats the best way to do this?

Munashe Tsododo
  • 247
  • 1
  • 5
  • 13

1 Answers1

1

A way to "force" the AjaxControlToolKit CalendarExtender to use a time component, is to append it using OnClientDateSelectionChanged and JavaScript.

<ajaxToolkit:CalendarExtender ID="ce1" runat="server" PopupButtonID="calImg" Enabled="true" Format="dd/MM/yyyy" TargetControlID="txtLeft" PopupPosition="TopRight" OnClientDateSelectionChanged="AppendTime"></ajaxToolkit:CalendarExtender>

and

<script language="javascript" type="text/javascript">
        //this script will get the date selected from the given calendarextender (ie: "sender") and append the
        //current time to it.
        function AppendTime(sender, args){
            var selectedDate = new Date();
            selectedDate = sender.get_selectedDate();
            var now = new Date();
            sender.get_element().value = selectedDate.format("dd/MM/yyyy") + " " + now.format("HH:mm");
        }
    </script>
Fandango68
  • 4,461
  • 4
  • 39
  • 74