Click to See Complete Forum and Search --> : problem in using QueryString[]


fongjeffrey
February 12th, 2004, 02:49 AM
Hi there,
I encountered a problem in using QueryString[] to retrieve parameters sent from the previous. I wanna pass an address from FirstPage to SecondPage. It fails if i have some special characters in the address field.
e.g.
In FirstPage.aspx.cs:
string addr1 = "12345 first street Apt #111"
string addr2 = "City, CA 1234"
Response.redirect("SecondPage?addr1="+addr1
+ "&addr2=" + addr2, true);


In SecondPage.aspx.cs, I try to retrieve the address
string addr1 = Request.QueryString["addr1"]
string addr2 = Request.QueryString["addr2"]

value of addr1 is "12345 first street Apt "
and value of addr2 is empty.

So everything after '#' sign is disappeared. Does anyone know why this happens and how to solve it.
Thanks a lot and have a great day!

Jeffrey

busyweb
February 13th, 2004, 02:43 AM
UrlEncode(String) may solve problem?
sample from MSDN
-----------------------------
URL encoding ensures that all browsers will correctly transmit text in URL strings. Characters such as ?, &,/, and spaces may be truncated or corrupted by some browsers so those characters cannot be used in ASP.NET pages in <A> tags or in query strings where the strings may be re-sent by a browser in a request string.
Example
[Visual Basic, C#, JScript] The following example URL-encodes a string before sending it to a browser client. In this example, the string MyURL will be encoded as "http%3a%2f%2fwww.contoso.com%2farticles.aspx%3ftitle+%3d+ASP.NET+Examples".
[Visual Basic]
Dim MyURL As String
MyURL = "http://www.contoso.com/articles.aspx?title = ASP.NET Examples"

Response.Write( "<A HREF = " & Server.UrlEncode(MyURL) & "> ASP.NET Examples <br>")
-----------------------------