Click here to Skip to main content
15,922,407 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
//Here is the string i am passing
C#
string myItem = "Love & Drugs";

C#
NavigationServices.Navigate(new Uri(string.Format("/Views/Page.xaml?item={0}",myItem)));


//this is how i retrieve it in OnNavigatedTo method

C#
MyTextBox.Text = NavigationContext.QueryString["item"];


//output is
C#
Love


My question is why isn't the rest of the string starting from "& Drugs" being passed or retrieved or i'm i doing something wrong??
Posted
Updated 12-Sep-14 7:22am
v2
Comments
Sergey Alexandrovich Kryukov 12-Sep-14 22:16pm    
Because '&' is used to delimiter parameters passed in URL.
Why using this way of passing data in HTTP request at all?
—SA

You need to encode the URL.[^]

Add using System.Net; at the top of your code file.
Use the the WebUtility.UrlEncode method[^] to encode the URL:
C#
string encodedItem = WebUtility.UrlEncode(myItem);
NavigationServices.Navigate(new Uri(string.Format("/Views/Page.xaml?item={0}",encodedItem)));
 
Share this answer
 
v2
Comments
job mwa 12-Sep-14 14:28pm    
Thank you very much for your detailed answer i appreciate it very much, Be blessed
Thomas Daniels 12-Sep-14 14:29pm    
You're welcome!
Sergey Alexandrovich Kryukov 12-Sep-14 22:16pm    
5ed.
—SA
Thomas Daniels 13-Sep-14 3:51am    
Thank you!
Dunno. Will HttpUtility.UrlEncode help?
http://msdn.microsoft.com/en-us/library/4fkewx0t(v=vs.110).aspx[^]
 
Share this answer
 
Comments
job mwa 12-Sep-14 14:27pm    
workedthanx for taking the time to help me out ... be blessed.
Sergey Alexandrovich Kryukov 12-Sep-14 22:17pm    
Right; a 5.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900