Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET AJAX > Ajax > Using RadTimePicker Class for overriding SelectedDate Property

Answered Using RadTimePicker Class for overriding SelectedDate Property

Feed from this thread
  • nitesh monga avatar

    Posted on Jul 7, 2009 (permalink)

    Hi there,

    I am trying to create a custom class which inherits radtimepicker class, and overrides the SelectedDate property of the class. but i am stuck at how to use this class with the radtimepicker control and let that control use the override property.

    why i want to do this is because we have lots for classic RadControls in our application now we are migrating them to the new ajax version, previously we were using asp:TextBox with JS to get the time value and to validate the value, with radtimepicker we get all the functionality we want without any extra JS :). the only problem is getting only the time value from the radtimepicker and not the date with that. while searching i found i can do that by using CType(radtimepicker .SelectedDate, DateTime).ToString("tt") but this will take a lot of time to implement :(. if i can just override the SelectedDate property and place the above .ToString("tt") with the GETTER it will be more easy :).

    i hope i am able to explain my problem. any example code will be a great help.

    Thanks
    Nitesh Monga

    Reply

  • Veli Veli admin's avatar

    Posted on Jul 10, 2009 (permalink)

    Hello nitesh,

    DateTime object's ToShortTimeString() probably is exactly what you need. So something like:

    radTimePicker.SelectedDate.Value.ToShortTimeString()  should work for you. If not, here is a sample approach:

    public class CustomRadTimePicker : RadTimePicker 
        public string SelectedTime 
        { 
            get 
            { 
                return this.SelectedDate.Value.ToShortTimeString(); 
            } 
            set 
            { 
                DateTime date; 
                if (DateTime.TryParse(value, out date)) 
                { 
                    this.SelectedDate = date; 
                } 
                else 
                { 
                    throw new Exception("String cannot be parsed to a valid DateTime."); 
                } 
            } 
        } 

    Public Class CustomRadTimePicker 
        Inherits RadTimePicker 
        Public Property SelectedTime() As String 
            Get 
                Return Me.SelectedDate.Value.ToShortTimeString() 
            End Get 
            Set 
                Dim [date] As DateTime 
                If DateTime.TryParse(value, [date]) Then 
                    Me.SelectedDate = [date] 
                Else 
                    Throw New Exception("String cannot be parsed to a valid DateTime."
                End If 
            End Set 
        End Property 
    End Class 


    Sincerely yours,
    Veli
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.

    Reply

  • Say Hello to Telerik's PivotGrid for ASP.NET AJAX, Silverlight, WPF and WinForms. Now packed with OLAP support.
  • nitesh monga avatar

    Posted on Jul 11, 2009 (permalink)

    Thank you for the sample code :). i already tested this code but i am unable to use this class with the rad controls :(. it always give a type cast exception..

    thanks
    Nitesh

    Reply

  • Answer Veli Veli admin's avatar

    Posted on Jul 13, 2009 (permalink)

    Hello Nitesh,

    What are trying to achieve? Can you share some sample code? Alternatively, try the ToShortTimeString() apporach.

    Regards,
    Veli
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.

    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET AJAX > Ajax > Using RadTimePicker Class for overriding SelectedDate Property
Related resources for "Using RadTimePicker Class for overriding SelectedDate Property"

ASP.NET AJAX Features  |  Documentation  |  Demos  | Step-by-step Tutorial  ]