locked
How can i get textbox text from Blank Page to MainPage? RRS feed

  • Question

  • I want to get the text from blankpage.xaml to Mainpage.xaml 

    i try to use this on MainPage.xaml:

    protected override void OnNavigatedTo(NavigationEventArgs e)
            {

      enter.Text = (App.Current as App).trytext;

    }

    but there is an error that trytext could not found so i use and if statement:

    protected override void OnNavigatedTo(NavigationEventArgs e)
            {
                if (enter.Text == "")
                {
                    enter.Text = "";
                }
                else
                {
                    enter.Text = (App.Current as App).trytext;
                }
            }

    but when i get the text from blankpage there is no text when i get back to mainpage

    please help!

    Thursday, January 30, 2014 1:01 PM

Answers

  • So..Page1 has a button. Pressing the button navigates to Page2 where there is a textbox/question. Then the app navigates BACK to Page1 when the player enters something in the textbox, and you need to know what text was entered in Page2.

    Based on that, I think you could still use the code I posted. When Page1 first loads, there will be no value in e.Parameter, but you just need to ignore that, much like in your original code (if e.Parameter = Nothing ...). But when navigating back from Page2 to Page1 e.Parameter will include the textbox text as a string.

    I would do something simpler, maybe instead of using two pages, just have a second 'layer' of UI that you collapse or display (e.g. a grid on top of your main grid which you hide -Page1- or display -Page2). Then there is never any need to move data around between pages - you could still access the textbox directly because you will always be on the same page.


    I'm a self-taught noob amateur. Please take this into account when responding to my posts or when taking advice from me.

    Thursday, January 30, 2014 2:59 PM

All replies

  • A better way would be to transfer the text when you navigate pages, but I think the solution to the way you're doing it might be to store the text somewhere other than the Textbox, such as a public property. You should then be able to access this property via the CurrentApp object like you are currently trying.

    I'm not sure how to set up a property in C#, but basically make a public property and set it's value to be whatever is entered in the text box. Then instead of trying to access the Textbox text from the other page access the property instead.


    I'm a self-taught noob amateur. Please take this into account when responding to my posts or when taking advice from me.

    Thursday, January 30, 2014 1:23 PM
  • is there any code can i see from you because im a hard learner when it comes to dictation im am more on example or visualization. sorry please help!
    Thursday, January 30, 2014 1:47 PM
  • Unfortunately I don't know C#...but this code should let you pass the text to your other page using a navigation parameter:

    When you navigate, do it like this (i.e. put the text you want to send as the navigation parameter):

    this.frame.navigate(typeof(MainPage), inputBox.Text);

    then, in your OnNavigatedTo handler:

    protected override void OnNavigatedTo(NavigationEventArgs e)
             {
                   textFromPreviousPage = e.Parameter
             }

    e.Parameter will be whatever you sent from the previous page.


    I'm a self-taught noob amateur. Please take this into account when responding to my posts or when taking advice from me.

    Thursday, January 30, 2014 1:56 PM
  • but the first thing that will run is the mainpage so e.Parameter is null it will not run :(
    Thursday, January 30, 2014 2:03 PM
  • Can you explain in a bit more detail what you are actually trying to do? Why are you trying to get data from a page that doesn't yet exist?

    Where is the text originating? Why are you trying to access it on MainPage (instead of originating it on MainPage, for example)?


    I'm a self-taught noob amateur. Please take this into account when responding to my posts or when taking advice from me.

    Thursday, January 30, 2014 2:07 PM
  • im trying to get the text from BlankPage.xaml to Mainpage.xaml but the mainpage will run 1st so that whe i get the text from blankpage it is null because. the text is originating from blankpage textbox.
    Thursday, January 30, 2014 2:16 PM
  • If blankpage isn't yet loaded why are you trying to get text from it? What is happening in your app that makes you try to get text from a page that hasn't been loaded yet? A textbox is for user input. The user can't input anything until the page has been shown to them.

    You can't access things on a page if the page hasn't been loaded. If you need text from a textbox on Page1 to use in Page2 then you need to first load Page1, input the text, then send it to Page2 in a navigation.

    I don't understand what you're trying to do.


    I'm a self-taught noob amateur. Please take this into account when responding to my posts or when taking advice from me.

    Thursday, January 30, 2014 2:24 PM
  • here i explain what im trying to do:

    i have a button question that will go to another xaml page from mainpage and in that xaml page there is a question that player must input the answer. so i want to get the text that player input to mainpage. can you understand it now? im really sorry it is hard for me to speak english so that i cant explain to you well

    Thursday, January 30, 2014 2:28 PM
  • So..Page1 has a button. Pressing the button navigates to Page2 where there is a textbox/question. Then the app navigates BACK to Page1 when the player enters something in the textbox, and you need to know what text was entered in Page2.

    Based on that, I think you could still use the code I posted. When Page1 first loads, there will be no value in e.Parameter, but you just need to ignore that, much like in your original code (if e.Parameter = Nothing ...). But when navigating back from Page2 to Page1 e.Parameter will include the textbox text as a string.

    I would do something simpler, maybe instead of using two pages, just have a second 'layer' of UI that you collapse or display (e.g. a grid on top of your main grid which you hide -Page1- or display -Page2). Then there is never any need to move data around between pages - you could still access the textbox directly because you will always be on the same page.


    I'm a self-taught noob amateur. Please take this into account when responding to my posts or when taking advice from me.

    Thursday, January 30, 2014 2:59 PM
  • can you show me it to me? just like i said im really sorry because i im not a learner with dictation :( sorry please help me
    Thursday, January 30, 2014 3:13 PM
  • i finally get it thank you so much mr.pumpkinszwan!
    Thursday, January 30, 2014 3:41 PM