Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

WP7 DatePicker returns to original value after edit

Posted on 2011-04-20
9
Medium Priority
?
1,264 Views
Last Modified: 2014-11-12
I have a page in my WP7 app that allows the user to add or edit a date.  I use the DatePicker control from the WP7 Toolkit referenced here : http://windowsphonegeek.com/articles/wp7-datepicker-and-timepicker-in-depth--api-and-customization.  When I add a date everything works fine and the date is added successfully.  

The problem comes when I try to edit that date.  

The process that I use is as follows:
When the page loads, I look for an edit value sent to it.  IF the edit value is sent, then I set the DatePicker to the original date which I look up in the underlying class:

datePicker1.value = originalDate

The DatePicker control gets the correct value and displays it.  When I select the field again the full screen selection choice shows up, and I can edit the date.  However when I click 'Save' and it reloads the screen that the control is on, the control is set back to the original date -- not the modified date.  

I am using the same process to change other fields -- names, addresses, etc. and don't have any problems with them.  Only the Datepicker control is causing a problem  
0
Comment
Question by:VoodooFrog
  • 5
  • 4
9 Comments
 
LVL 48

Expert Comment

by:Mikal613
ID: 35439971
do you have the date set in the xaml?
0
 

Author Comment

by:VoodooFrog
ID: 35441696
no -- the date is only set by that line of code that I put in the question.

the declaration of the date picker: <toolkit:DatePicker Name="datePicker1" Height="74" Width="179" Grid.Row="1" Grid.Column="1" />

0
 
LVL 48

Expert Comment

by:Mikal613
ID: 35442386
which method calls "datePicker1.value = originalDate" ??  Is it on the PAge_Loaded event?
0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 

Author Comment

by:VoodooFrog
ID: 35442636
it is the OnNavigatedTo:

 protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            selectedItem = Convert.ToInt16(NavigationContext.QueryString["edit"].ToString());
            Person p = GetPersonFull(selectedItem);
            textName.Text = p.Name;
            datePicker1.Value = p.Birthdate;

       }

Open in new window


I am thinking after reading your question that the problem is that the 'edit' parameter is being sent to the page that I am using after selecting the date from the popup page launched by the datepicker control.  

So I guess my question is, how do I prevent this?  I would rather not have to create a new control myself, since there is a control already out there that looks like it does what I need.  I don't know how to:

a: modify the second screen on the datepicker control,  

b) check for the prior page and add an exclusion to setting the value if the calling page was the datepicker page

c) remove the 'edit' parameter from being sent by the datepicker selection page

I would assume that any of those three would work, but I don't know the process for any of them.  
0
 
LVL 48

Expert Comment

by:Mikal613
ID: 35442655
why are you reloading the screen after a save. Just have logic to load the data not the page after a save.
0
 

Author Comment

by:VoodooFrog
ID: 35443001
I am not loading the screen purposefully -- the control does that.  on the date picker control, when you select it to make a change it loads a new page.  I think that this page is re-calling my edit page which is reloading the original value.  

The control I am using is from the windows phone toolkit.  
0
 
LVL 48

Accepted Solution

by:
Mikal613 earned 2000 total points
ID: 35443514
I currently use that control, and dont have that issue. Maybe make a flag to show if the page loaded and based on that you will use the data from the date control.
0
 

Author Comment

by:VoodooFrog
ID: 35444422
I can try that.  I am assuming there should be some way to handle this more natively than that though.  I may not fully understand what is happening -- it seems odd that the datepicker page would re-send the query to the source page.  
0
 

Author Closing Comment

by:VoodooFrog
ID: 35445384
setting a flag worked -- I was already changing the PageTitle to say edit instead of add -- so looking for that change made all the difference.

I am still not sure why the Datepicker page is sending the query string again, but oh well!  

Thanks for the help.
0

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Screencast - Getting to Know the Pipeline
Suggested Courses
Course of the Month20 days, 16 hours left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question