This is a migrated thread and some comments may be shown as answers.

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

2 Answers 90 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
Dave Navarro
Top achievements
Rank 2
Dave Navarro asked on 23 Jan 2012, 09:34 PM

Hello,

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 Answers, 1 is accepted

Sort by
0
Richard
Top achievements
Rank 1
answered on 24 Jan 2012, 09:04 PM
Dave:

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.

Cheers!
0
Dave Navarro
Top achievements
Rank 2
answered on 27 Jan 2012, 07:20 PM
Hello,

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.
<telerik:RadDateTimePickerID="rdtIncFrom"runat="server">
    <DateInputDateFormat="dd/MM/yyyy hh:mm">
    </DateInput>
</telerik:RadDateTimePicker>
<asp:ButtonID="btn1"runat="server"Text="PostBack"/>
<asp:LabelID="lbl1"runat="server"></asp:Label>
 
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
Tags
Calendar
Asked by
Dave Navarro
Top achievements
Rank 2
Answers by
Richard
Top achievements
Rank 1
Dave Navarro
Top achievements
Rank 2
Share this question
or