LethalMachine
LethalMachine

Reputation: 207

How do i pass a string variable to another page without using Uri in Windows Phone 7?

The string I want to pass from one WP page to another contains the character '#'. So when I pass this string using Uri, the rest of the string starting from '#' gets truncated which causes a json parse error. So how else can I pass this string? I don't want to modify the string and pass it as the downloaded string varies from user to user.

Here is my code:

NavigationService.Navigate(new Uri("/Home.xaml?jsonData=" + text, UriKind.Relative));

Here is my json string contained in "text" variable:

{"name":"RALPH K. TELL","course":"","attendence":[{"name":"OBJECT ORIENTED ANALYSIS AND DESIGN","type":"Theory","conducted":"14","present":"14"},{"name":"C#AND.NET FRAMEWORK","type":"Theory","conducted":"17","present":"16"}]}

Here is how I get the value in the next page:

String jdata = NavigationContext.QueryString["jsonData"];

Upvotes: 0

Views: 65

Answers (1)

Kulasangar
Kulasangar

Reputation: 9444

If any of your query strings contain characters that are considered invalid in a Uri what you're doing will fail, as you've discovered. You need to use Uri.EscapeDataString to escape any illegal characters first. Change the code you've posted to the following:

NavigationService.Navigate(new Uri("/Home.xaml?jsonData=" + Uri.EscapeDataString(text), UriKind.Relative));

Have a look at these threads Uri.EscapeDataString() - Invalid URI: The Uri string is too long

HttpUtility.UrlEncode in Windows Phone 7?

Hope it helps!

Upvotes: 2

Related Questions