How to use the WinJS.Navigation.navigate function state property for transfering data from one page to other pages.Generally the WinJS.Navigation.navigate function can take the parameter of object Type like place and state.The palce to navigate to. Generally the place is a string containing the URL, but it may be anything.The state is a user-defined object that represents the navigation state that may be accessed through state.its retruning a value of Type promise.A promise that is completed with a value that indicates whether or not the navigation was successful.
In following way we can use the state property of the WinJS.Navigation.
step 1: Let’s first modify the Home.html of Home page control.
Navigation Template
First Page Control
Enter Name please
Enter Id Navigate To Details
Step 2: Then we have to add the following code snipet to the Home.js
document.getElementById("btnDetails").addEventListener("click", MoveTo); //Navigating to the details page function MoveTo() { var name = document.getElementById("enteredName").value; var id = document.getElementById("enteredId").value; WinJS.Navigation.navigate("/pages/Details.html", { Name: name, Id: id }); }
Step 3:
Then we have to gets or sets a user-defined object that represents the state associated with the current place. lets add the following code snipet to the details.html of the details page control to bind the value return from the WinJS.Navigation.state
Details Page Control
Then in the Details.js we need to add the following code
var myState = WinJS.Navigation.state; if(document.getElementById("name")) document.getElementById("name").innerHTML = myState.Name; if(document.getElementById("numberId")) document.getElementById("numberId").innerHTML = myState.Id;
In this way we can use the state property of the WinJS.Navigation