Reputation: 2118
I create a hyperlink that when clicks generates a url like so:
And I read it into a text box like so:
Me.txtTags.Text = CType(Request.QueryString("Tag"), String)
But the result of this is that the textbox txtTags will only contain C and doesnt have the ++. I tried http://somesite?MyTag=C# and the # is missing as well. But if I look at the address bar these values are there....
Upvotes: 0
Views: 4206
Reputation: 15301
You should Encode the string when you are generating that link using Server.UrlEncode
, here is an example:
MyHyperLink.NavigateUrl = "http://www.mysite.com/default.aspx?mytag=" & Server.UrlEncode("C++")
And when you are trying to process it in default.aspx, you should decode it using Server.URLDecode
, here is an example:
Me.txtTags.Text = Server.UrlDecode(Request.QueryString("mytag")) 'This will show "C++" without quotes in txtTags textbox.
You may want to read more about Server.UrlEncode
here and about Server.UrlDecode
here.
Upvotes: 1
Reputation: 30125
You need to use UrlEncode
when you building url and UrlDecode
when you are trying to read url params
MyURL = "http://www.contoso.com/articles.aspx?title=" & Server.UrlEncode("C#")
Upvotes: 2
Reputation: 1167
Here is a list of Special Characters for Query String
http://permadi.com/tutorial/urlEncoding/
Upvotes: 0
Reputation: 1157
#
is used as the anchor tag, so it's not a legal query param. It represents the end of the query string and segues into the beginning of the anchor string. I just ran into this problem myself yesterday :)
+
is generally used to encode spaces in URLs, so it won't show up in a query string either.
Upvotes: 4
Reputation: 102
'#' can't be used since it is used for HTML anchors. Don't know the exact answer for the + though
Upvotes: 1
Reputation: 8337
try
Me.txtTags.Text = Server.UrlDecode(Request.QueryString("MyTag"))
Upvotes: 5