0

Why my string email only contains the value of aux on the OnNavigatedTo method? Why when I try to use my string email on the Main method the value becomes null?

 public string email;

 protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            string aux;
            base.OnNavigatedTo(e);
            if (NavigationContext.QueryString.TryGetValue("email", out aux))
                email = aux;
        }
Gustavo Mendonça
  • 1,925
  • 3
  • 15
  • 26
  • we don't know what's wrong with your code can you provide more information..for example `I would be that you did not Debug \ Step` through the code for starters.. also what is the value of `e` in this line `base.OnNavigatedTo(e);` I also wonder why you need to call base.OnNavigate` I will post something that you should try – MethodMan Feb 09 '15 at 23:14
  • I forgot to say, but I am developing a windows phone app. The `base.OnNavigatedTo(e)` it is part of the method and it is generated automatically by Visual Studio. The function of this method is that when my app navigate to this page will run the code that is inside this method. The error it is not the method I guess, the error is in `aux` maybe.. – Gustavo Mendonça Feb 09 '15 at 23:21
  • can you explain what the error is if any so that we are all on the same page.. I will remove my answer as well can you also show what the query string looks like in the url as well...? – MethodMan Feb 09 '15 at 23:27
  • Ok, I want to pass a string that are on the MainPage to this page. In the MainPage the url is: `NavigationService.Navigate(new Uri("/ColetoresPage.xaml?email=" + txtEmail.Text, UriKind.RelativeOrAbsolute));` but the problem is in the string aux I think. I replaced `email = aux` for `MessageBox.Show(aux)` and it worked, it shows a box with the right email. So, why when I try to pass the aux to the string email it does not work? – Gustavo Mendonça Feb 09 '15 at 23:37
  • 1
    I discovered that the problem is that my string email only contains the value of aux on the method `OnNavigatedTo` and when I try to use the string email on other place, his value is null. – Gustavo Mendonça Feb 10 '15 at 01:01
  • Glad you could figure out your problem @GustavoMendonca `The debugger works wonders I see` – MethodMan Feb 10 '15 at 15:16
  • Yeah, I figured out my problem but I don't discovered yet how to fix it. And, I did not used the debugger to find the problem, I just made few tests and discovered my problem. – Gustavo Mendonça Feb 11 '15 at 20:55

0 Answers0