WP7 DatePicker returns to original value after edit

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  
VoodooFrogAsked:
Who is Participating?
 
Mikal613Connect With a Mentor Commented:
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
 
Mikal613Commented:
do you have the date set in the xaml?
0
 
VoodooFrogAuthor Commented:
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
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
Mikal613Commented:
which method calls "datePicker1.value = originalDate" ??  Is it on the PAge_Loaded event?
0
 
VoodooFrogAuthor Commented:
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
 
Mikal613Commented:
why are you reloading the screen after a save. Just have logic to load the data not the page after a save.
0
 
VoodooFrogAuthor Commented:
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
 
VoodooFrogAuthor Commented:
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
 
VoodooFrogAuthor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.