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

Page_Loaded event seems to be the wrong place to put in code for doing calculations using controls on the page

4 Answers 52 Views
MaskedInput (Numeric, DateTime, Text, Currency)
This is a migrated thread and some comments may be shown as answers.
Rod
Top achievements
Rank 1
Rod asked on 27 Sep 2012, 03:36 PM
I've got 2 controls on a page, one for a request date and another for the date of birth of a client.  Both of these values come from a SQL Server database.  During the Page_Loaded event I had been trying to calculate the age of the client on the request date, however that's not working.  For some reason, which I don't understand, the date of birth of the client is wrong (it turns out to be today's date), during the Page_Loaded event.  However, once the page is actually displayed, it is correct.  I had thought Page_Loaded would have been the correct event to put this code, but that doesn't seem to be the case.
 
So, where should I put the age calculation code?  In what event?

The XAML for the first control is:
<telerik:RadMaskedDateTimeInput Name="radReqDate" MinWidth="80" TabIndex="0" FontWeight="Bold"
                               Value="{Binding RequestDate}" InputBehavior="Replace" TextMode="PlainText"
                               SelectionOnFocus="SelectAll" ValueChanged="radReqDate_ValueChanged" />

and the XAML for the second control is here:
<telerik:RadMaskedDateTimeInput Name="radDOB" EmptyContent="Enter DOB" MinWidth="80" TabIndex="14"
                               FontWeight="Bold" InputBehavior="Replace" TextMode="PlainText"
                               Value="{Binding Path=DateOfBirth, Mode=TwoWay}" ValueChanged="radDOB_ValueChanged" />

4 Answers, 1 is accepted

Sort by
0
Tina Stancheva
Telerik team
answered on 02 Oct 2012, 12:28 PM
Hi Rod,

From your description I gather that the RadMaskedDateTimeInput values are still not updated in the Loaded event handler of the page. However, as I am not sure how your layout is built, I am not sure what is causing the delay in the value update or if this is the cause for the issue.

This is why I prepared a sample solution to test your scenario and I wasn't able to reproduce the case. Can you please take a look at the project and let me know if I'm missing something? Also, you can use the data objects to calculate the age of the client - basically instead of using the Value property of the MaskedInput controls, you can calculate the age as this:
       var age = radReqDate.Year - radDOB.Year;

All the best,
Tina Stancheva
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Rod
Top achievements
Rank 1
answered on 02 Oct 2012, 02:27 PM
Hello Tina,

Thank you for your reply.  I don't have the Telerik controls 2012.2.912.40.  The last I had was 2011 Q2, I believe.  (I can't open your project without errors.)
0
Tina Stancheva
Telerik team
answered on 05 Oct 2012, 03:31 PM
Hi Rod,

I tested my solution with the Q2 2011 assemblies and I am still not able to reproduce the issue. Also, on our side the project can be correctly downloaded and it runs without any issues and this is why I am not sure why you're experiencing issues with it.

Can you try the solution I attached to this post - it uses the Q2 2011 dlls and it still claculates the age correctly. Let me know if I'm missing something.

Regards,
Tina Stancheva
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Rod
Top achievements
Rank 1
answered on 05 Oct 2012, 09:17 PM
WOW, you're right.  You're example worked fine.  I'm floored; don't know why your's does and mine doesn't.  (I'm getting an odd error in the VS 2010 designer when I open your project; something about not being able to load the file or assembly 'Telerik.Windows.Controls, Version=2011.2.712.40, but it didn't stop me from running it, and of course I can look through the XAML.)
Tags
MaskedInput (Numeric, DateTime, Text, Currency)
Asked by
Rod
Top achievements
Rank 1
Answers by
Tina Stancheva
Telerik team
Rod
Top achievements
Rank 1
Share this question
or