Click here to Skip to main content
15,896,111 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
how to include "#" in query string parameter

Am passing some values from one page to another using query string.
Its working as expected but if any one of the value in query string contains '#' then it doesn't work. Query string showing as empty. Unable to get values from query string.

URL: mypage.aspx?Valu1=AB C&Value2= 12 //Working

URL: mypage.aspx?Valu1=AB #C&Value2= 12 // Not Working
Posted

"#" is a special character in URLS - it's a "Jump" location on a page.

So to include it in a query string, just use the UrlEncode Method[^] to "translate" the whoile string into percent codes.
 
Share this answer
 
Instead pass %23
See the complete list here[^]
Now your URL: mypage.aspx?Valu1=AB %23C&Value2= 12 // Working

# needs to convert to be transmitted.

-KR
 
Share this answer
 
v3
The character # can also mean a hyperlink to an element with the specified ID. So, browser may be looking forward that element and if it does not exist it simply stops. URLs can be HTML encoded so that when you are going to use those special characters as values, they are decoded back to their actual forms, skipping the URL interpretation. Ever wondered why is a white-space written as %20?

Not just #, but other special characters can also be encoded so that they can also be used as data and not as a special character in URL, like & or = character sign. Please refer this, http://www.w3schools.com/tags/ref_urlencode.asp[^] to learn more on that.
 
Share this answer
 
v4
You can try . Not tested
Response.Redirect(Server.UrlEncode("mypage.aspx?Valu1=AB#C&Value2= 12"));
 
Share this answer
 
replace the # by %23 under the query string.
 
Share this answer
 
Comments
ZurdoDev 2-Nov-15 16:02pm    
You should use the built-in method for encoding urls, as mentioned in other solutions.

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