How to set date and time from codebehind in Page_Load event?

3 posts, 0 answers
  1. Dave Navarro
    Dave Navarro avatar
    150 posts
    Member since:
    Jul 2005

    Posted 23 Jan 2012 Link to this post


    I have a page that has two calendar controls on it. One is for indicating a start date / time and one is for indicating an end date / time. These values are ultimately saved in the database.

    When a user returns to their record and wishes to update these values, I'd like to show them what they were previously set to. I'm able to save and retrieve the date value by wiring up the SelectedDate.Value property. But this does not help me get the time.

    I'm also not sure how to set the time once I have the value from the server. I'm able to set the date but not the time.

    Please let me know how I'd go about setting the date AND time values in my Page_Load event.

    Many thanks in advance,

    ~ Dave

  2. Richard
    Richard avatar
    479 posts
    Member since:
    Nov 2011

    Posted 24 Jan 2012 Link to this post


    Would it be possible for you to post your form and code behind pages, and a screenshot of your form? This would make it easier to edit and update the application to produce the required functionality.

  3. Dave Navarro
    Dave Navarro avatar
    150 posts
    Member since:
    Jul 2005

    Posted 27 Jan 2012 Link to this post


    Well, with the help of our support desk I was able to get this litte issue resolved. Turns out it was one of the 'self inflicted' issues... Here's a snippet of code that worked on a new test page.
        <DateInputDateFormat="dd/MM/yyyy hh:mm">
    protectedvoidPage_Load(objectsender, EventArgs e)
        if(rdtIncFrom.SelectedDate != null)
            lbl1.Text = rdtIncFrom.SelectedDate.Value.ToString();

    Once I saw the code work correctly I triple checked my Page_Load event and found that I was NOT checking for a null value before setting the new date/time.

    So, I'm sorry to bother everyone with this and I do very much appreciate the help and support I get from our Telerik Forums!

    I'll call this 'case closed' and lesson learned!

    ~ Dave
Back to Top