Click here to Skip to main content
15,889,462 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Why The last parameter in the query string is ignoring the space?
How to retain it.

C#
string str = "Default2.aspx?test=1   &JobId=1   ";
Response.Redirect(str);


When i move to Default2.aspx page, i will obtain "test" as 1 followed by three spaces
but JobId as 1 only i.e with out any space.
Posted
v2
Comments
Harshad-HBK 10-Dec-12 4:33am    
are you passing query string parameters dynamically? please explain in details.
[no name] 10-Dec-12 4:35am    
What you're up to ?
Harshad-HBK 10-Dec-12 4:38am    
string str = "Default2.aspx?test=1 &JobId=1 ";
....

here value of querystring 'test' & 'jobid are dynamic or static ??
are they coming from database or you are defining it in the code ??
AnkitGoel.com 10-Dec-12 4:37am    
have u tried passing & nbsp ; instead of space?

1 solution

You have to use HttpUtility.UrlEncode()[^] to get what you expect in querystring.

Just do as below.
C#
string str = "Default2.aspx?test=" + HttpUtility.UrlEncode("1   ") + "&JobId=" + HttpUtility.UrlEncode("1   ");

Response.Redirect(str);

Thanks...
 
Share this answer
 
Comments
pradiprenushe 10-Dec-12 5:05am    
Correct one 5+
Thanks @pradiprenushe.
Thanks for accepting the answer @srikanth.enigma.

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