Basic Date Picker Forums

Welcome to Basic Date Picker Forums Sign in | Join | Help
in Search

TimePicker a time range

Last post 02-17-2008, 1:17 AM by geoffrey.mcgill. 16 replies.
Sort Posts: Previous Next
  •  02-04-2008, 3:30 PM 1421

    TimePicker a time range

    Hi,
    I'm using the timepicker control without an associated datepicker control. I want to specify a specific time range for the timepicker to display. For example for it to display from 9:00am -  17:00pm . I have tried adding items to the timepicker within the range I need but this still displays the all the hours in a day, my code is as below:

     
    /* aspx ---------------------------------------------------------------------------*/

    <BDP:TimePicker ID="TimePicker1" TimeFormat="t" MinuteIncrement="1" DisplayType="MultipleDropDownList"
         runat="server" CssClass="TimePickerInput">
    </BDP:TimePicker>

    /* C# --------------------------------------------------------------------------------*/
     
                   int earliestHours = 9;
                        int latestHours = 20;
               
            for (int hour = earliestHours; hour <= latestHours; hour++)
                        {
                            string hourString = formatHour(hour.ToString());
                            ListItem item = new ListItem(hourString, hour.ToString());
                            TimePicker1.Items.Add(item);
                        }
    /*------------------------------------------------------------------------------------ */

    There is probably something I have overlooked that already does this, any help would be very much appreciated.
    Thanks
    Nav


  •  02-05-2008, 11:47 AM 1423 in reply to 1421

    Re: TimePicker a time range

    Hi nav323,

    I thought there was a MinimumTime and MaximumTime property on the TimePicker, but apparently there is not. I just added both.

    The MinimumTime and MaximumTime properties will only apply when the DisplayType is one of the following:

    1. SingleDropDownList, or
    2. MultipleDropDownList and the TimeFormat is in 24 hour time. Example 09:00 - 17:00

    Example

    <%@ Page Language="C#" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                // Using TimeSpan
                this.TimePicker1.MinimumTime = new TimeSpan(9, 0, 0);
               
                // Using DateTime
                //this.TimePicker1.MinimumTime = DateTime.Today.AddHours(9).TimeOfDay;
               
                // Using TimeSpan
                this.TimePicker1.MaximumTime = new TimeSpan(18, 0, 0);
               
                // Using DateTime
                //this.TimePicker1.MaximumTime = DateTime.Today.AddHours(18).TimeOfDay;
            }
        }
    </script>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>TimePicker : MinimumTime & MaximumTime</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
       
            <bdp:TimePicker
                ID="TimePicker1"
                runat="server"
                DisplayType="MultipleDropDownList"
                TimeFormat="HH:mm"
                />
       
        </div>
        </form>
    </body>
    </html>

    Another option that may be useful in this scenario is to use the TimeRangeValidator control.

    The new build with the MinimumTime and MaximumTime properties will be available before the end of today.

     


    Thanks,
    Geoffrey McGill
    ----------------------------------------
    Coolite Inc.
    Email: support [at] coolite [dot] com
    Phone: +1(888)775-5888
  •  02-05-2008, 2:21 PM 1425 in reply to 1423

    Re: TimePicker a time range

    Hi Geoff,

    \Thanks for the reply and adding the extra properties they will make things easier for me. With regards to the latest build will we get an email if we have already bought the product with a link to the latest build?

    Thanks,
    Naveen . H
  •  02-05-2008, 3:33 PM 1426 in reply to 1425

    Re: TimePicker a time range

    Hi Naveen,

    The new builds have been uploaded. You can download at http://www.basicdatepicker.com/download/

    This build is a free upgrade to all existing licenses.

    Please let us know if you find any 'issues' and we'll do our best to help out.


    Thanks,
    Geoffrey McGill
    ----------------------------------------
    Coolite Inc.
    Email: support [at] coolite [dot] com
    Phone: +1(888)775-5888
  •  02-06-2008, 6:40 AM 1430 in reply to 1426

    Re: TimePicker hours dropdown v1.4.0.37271

    Hi Geoff thank you for uploading the properties to the latest build. I have a new issue when trying out v1.4.0.37271 of TimePicker. My code declaring the timepicker in the aspx is below:
     
    Aspx:
    --------------------------------------------------------------
    <BDP:TimePicker ID="TimePicker1" TimeFormat="t" MinuteIncrement="1" DisplayType="MultipleDropDownList" runat="server" CssClass="TimePickerInput">
    </BDP:TimePicker>

    I am not trying to change the minimum or maximum properties of the timepicker or any of its other properties in the codebehind. The problem is that no hours are displayed in the hours drop down list but the minutes are displayed fine in the minutes drop down of the mutipledropdownlist.

    Many thanks,
    Naveen

  •  02-06-2008, 10:47 AM 1432 in reply to 1430

    Re: TimePicker hours dropdown v1.4.0.37271

    Hi Naveen,

    The bug with the hours not being rendered has been fixed. A new build has been uploaded to http://www.basicdatepicker.com/download/

    Hope this helps.


    Thanks,
    Geoffrey McGill
    ----------------------------------------
    Coolite Inc.
    Email: support [at] coolite [dot] com
    Phone: +1(888)775-5888
  •  02-09-2008, 5:07 AM 1438 in reply to 1432

    Re: TimePicker hours dropdown v1.4.0.37271

    Hi Geoffery,

    Sorry for not replying sooner. I have tested the build and the hours and minutes are being rendered fine so thank you for the fix.

    Though I'm having a issue when setting MaximumTime and MinimumTime property of the  TimePicker. The code  you replyed with works fine although not quite how I expected. For example if I do as below:

     this.TimePicker1.MinimumTime = new TimeSpan(9, 30, 0);
     this.TimePicker1.MaximumTime = new TimeSpan(18, 0, 0);

    When the page loads, and 9 is selected in the hours dropdown I was expecting the minutes to be rendered from 30-59, and when the hours 10-18 are selected the full set of minutes to be rendered 1-59 would be rendered in the minutes dropdown.

    My aspx code is below:
    <bdp:TimePicker
                                    ID="TimePicker1"
                                    runat="server"
                                    DisplayType="MultipleDropDownList"
                                    TimeFormat="HH:mm"
                                    MinuteIncrement ="1"
                                    InputStyle-Width="60px"
                                    />

    Many thanks,
    Naveen

  •  02-10-2008, 8:06 PM 1441 in reply to 1438

    Re: TimePicker hours dropdown v1.4.0.37271

    Hi Naveen,

    At the moment, the TimePicker does not include built-in client-side functionality required to switch out the list items when the Min or Max Time are set to something other than 00 minutes.

    It should be possible to implement this functionality with custom logic by tapping into the OnClientSelectionChanged property.

    I've added this feature request to the list of items to implement. I can't give you date as to when this functionality will be included, but I will keep this thread updated with our progress.


    Thanks,
    Geoffrey McGill
    ----------------------------------------
    Coolite Inc.
    Email: support [at] coolite [dot] com
    Phone: +1(888)775-5888
  •  02-11-2008, 8:42 AM 1444 in reply to 1441

    Re: TimePicker hours dropdown v1.4.0.37271

    Hi Geoffrey,

    Thanks for the reply, I am looking to start the minutes at 30 onwards when the hour 9 is selected in the hours dropdown, in the onclientselectionchanged event. Please could you tell me which method I can use to set the minute start value to 30?
    Thanks,
    Naveen
  •  02-13-2008, 2:13 PM 1447 in reply to 1444

    Re: TimePicker hours dropdown v1.4.0.37271

    Hi Naveen,

    Functionality has been added to the TimePicker to automatically handle the syncing of the DropDownList controls client-side (JavaScript) when a MinimumTime is set. The sync will only happen when the DisplayType is "MultipleDropDownList".

    The sample below demonstrates a full sample.

    We also added the following functions to the TimePicker's client-side JavaScript API:

    1. .getMinimumTime() - returns a TimeSpan
    2. .setMinimumTime(TimsSpan time)
    3. .getMaximumTime() - returns a TimeSpan
    4. .setMaximumTime(TimeSpan time)

    All the new TimePicker code will be available in the next build, which should be published to the Download page shortly.

    Hope this helps.

    Example

    <%@ Page Language="C#" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.TimePicker1.MinimumTime = new TimeSpan(9, 30, 0);
                this.TimePicker1.MaximumTime = new TimeSpan(18, 0, 0);
            }
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            this.Label1.Text = this.TimePicker1.SelectedTimeFormatted;
        }
    </script>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>TimePicker : MinimumTime & MaximumTime</title>
         
    </head>
    <body>

        <form id="form1" runat="server">
        <div>
            <bdp:TimePicker
                ID="TimePicker1"
                runat="server"
                DisplayType="MultipleDropDownList"
                TimeFormat="HH:mm"
                Nullable="false"

                MinuteIncrement ="1"
                />
        </div>
        <p><asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" /></p>
        <p><asp:Label ID="Label1" runat="server" /></p>
        </form>
    </body>
    </html>

    Thanks,
    Geoffrey McGill
    ----------------------------------------
    Coolite Inc.
    Email: support [at] coolite [dot] com
    Phone: +1(888)775-5888
  •  02-13-2008, 3:06 PM 1450 in reply to 1447

    Re: TimePicker hours dropdown v1.4.0.37271

    Hi Geoffrey,

    Thank you for your reply. I appreciate that. Can I confirm that if I use the the TimePicker as below and use the .setMinimumTime(TimeSpan time) function as such TimePicker1.setMinimumTime(new TimeSpan(9,30,0)) and TimePicker1.setMaximumTime(new TimeSpan(17,0,0)).

    Am I right that this will render the options 30 - 59 in the minutes dropdown when 9 is selected in the hours dropdown, and will render the options 0 -59 in the minutes dropdown when any hour from 10 to 17 is selected?

    Apologies for maybe going over the same point again, but this is the functionality I really need.

    Many thanks for your continued support,
     Naveen
  •  02-13-2008, 3:14 PM 1452 in reply to 1450

    Re: TimePicker hours dropdown v1.4.0.37271

    yes.

    We responded to the support request you emailed to us earlier. Attached to that email is a copy of the latest .dll. If you did not receive that email, just let us know.

    Give the .dll a try and let us know if it functions as you expect.


    Thanks,
    Geoffrey McGill
    ----------------------------------------
    Coolite Inc.
    Email: support [at] coolite [dot] com
    Phone: +1(888)775-5888
  •  02-13-2008, 5:36 PM 1455 in reply to 1450

    Re: TimePicker hours dropdown v1.4.0.37271

    Hi Naveen,

    The new installers and manual installation packages have been updated.

    You can download the latest release from http://www.basicdatepicker.com/download/.

    Hope this helps.


    Thanks,
    Geoffrey McGill
    ----------------------------------------
    Coolite Inc.
    Email: support [at] coolite [dot] com
    Phone: +1(888)775-5888
  •  02-14-2008, 2:38 PM 1458 in reply to 1452

    Re: TimePicker hours dropdown v1.4.0.37271

    Hi Geoffrey,

    I have added the latest build to our application and had a chance to test it. The minimum time and maximum time for timepicker seem to function well but only when the page is not postback.

    When the IsPostback = true for the page and I try and set the minimum time and maximum time I get some slightly strange behaviour.  For example if I try in the Page_Load:
    If (Page.IsPostback)
    {
     timepicker1.minimumtime(9,30,0)
    timepicker1.maximumtime(16,30,0)
    }

    Then the timepicker select 9:30 on the page but the user is able to select all hours before 9 and all hours after 16 from (00 -23).  Are there postback options that could be altered that would help here?

    One other minor point is that when the time picker is displayed and the user selects 10 in the hours 30 is still left selected in the minutes dropdown.

    If you could give me an rough-ish estimate how long it may be before this functionality is implemented (eg few days, a week or two) I would be very grateful to you,
    Thanks Naveen
  •  02-15-2008, 3:45 PM 1459 in reply to 1458

    Re: TimePicker hours dropdown v1.4.0.37271

    Hi Naveen,

    We did some more testing and can't seem reproduce the PostBack issue you noted above. Does the sample we posted earlier work for you? http://forums.basicdatepicker.com/forums/permalink/1421/1447/ShowThread.aspx#1447

    "One other minor point is that when the time picker is displayed and the user selects 10 in the hours 30 is still left selected in the minutes dropdown."

    Maybe I misunderstand your point, but I think this is the desired functionality. If the SelectedTime is intially 9:30 and I change the Hour DropDownList to "10", the "30" Minute value should NOT change.

     


    Thanks,
    Geoffrey McGill
    ----------------------------------------
    Coolite Inc.
    Email: support [at] coolite [dot] com
    Phone: +1(888)775-5888
  •  02-16-2008, 2:40 PM 1463 in reply to 1459

    Re: TimePicker hours dropdown v1.4.0.37271

    Hi Geoffrey, Please see my code below that produces the postback issue when using the minimum and maximum properties of timepicker v1.4. The minor issue wasn't made clear in my last post, it was regarding the minimumtime property not the selectedtime property. If I set the minimumtime to 9:30, I would expect it to have the selectedtime of 9:30 which it does. But when I change the hour dropdown list to '10', then '30' minute value is still selected , ideally '00' should be selected in the minutes dropdown when changing to an hour that is not 9. Thanks a lot for the continued support, Naveen // ******************** aspx *************************************** Untitled Page
    \\******************************** Codebehind ***************************** public partial class WebForm1 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void TimeTest_SelectionChanged(object sender, EventArgs e) { if (Page.IsPostBack == true) { TimeTest.MinimumTime = new TimeSpan(9, 30, 0); TimeTest.MaximumTime = new TimeSpan(17, 30, 0); } } }
  •  02-17-2008, 1:17 AM 1465 in reply to 1463

    Re: TimePicker hours dropdown v1.4.0.37271

    Hi Naveen,

    Looks like there was a small issue with the Minimum/MaximumTime properties during a PostBack if they they had not been set pre-postback or were changed during the postback. The Hour DropDownList was not recreating it's ListItems correctly to match the new min/max time. The problem has been fixed. A new build will be available shortly.

    Other than that, everything appears to work great.

    I can't say I agree with you regarding your suggestion of changing the Minute DropDownList when the Hour changes. If I choose "9:30" and then change the Hour to "10", I would not expect (nor want) the Minutes to change to "00".

    Likewise, if I've picked "10:37" and then change the Hour to "9", I would not expect (nor want) the Minutes to change to "30".


    Thanks,
    Geoffrey McGill
    ----------------------------------------
    Coolite Inc.
    Email: support [at] coolite [dot] com
    Phone: +1(888)775-5888
View as RSS news feed in XML
 
Powered by Community Server, by Telligent Systems