Search code examples
windows-phone-7navigation

Pass Data On Page NavigationService.GoBack()


I created a navigation event where Page1 TextBox1.Text Transfers To Page2 TextBox2.Text

My Page1 Code:

    private void button1_Click(object sender, System.Windows.Input.GestureEventArgs e)
    {
        string uri = "/Page1.xaml?Text=";
        uri += TextBox1.Text;
        NavigationService.Navigate(new Uri(uri, UriKind.Relative));
    }

My Page2 Code:

    protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
    {
        base.OnNavigatedTo(e);
        IDictionary<string, string> parameters = this.NavigationContext.QueryString;
        if (parameters.ContainsKey("Text"))
        {
            TextBox2.Text = parameters["Text"];
        }
    }

Above code works fine when Navigating from Page1 to Page2 but it give error while trying to use

    NavigationService.GoBack();  method

when i am passing the text from page2 to page1 i dont want to create another instance of page1 I just want to go back to old instance but while doing that my text is not transferring PLEASE HELP...


Solution

  • Check this Link hope so it will help you

    Pass Values Between Pages

    On page2 the data is saved using

    PhoneApplicationService.Current.State["Text"] = txtboxvalue.Text;
    

    and can be get at page1 using

    protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
            {
                base.OnNavigatedTo(e);
                if (PhoneApplicationService.Current.State.ContainsKey("Text"))
                    txtvalue.Text = (string)PhoneApplicationService.Current.State["Text"];
    
    
            }