0

I have two files htmlpage1.htm and webform1.aspx

htmlpage1.htm contains a anchor tag with href="webform1.aspx?name=abc+xyz".

When i try to access the querystring in page_load of webform1.aspx, i get "abc xyz" (abc [space] xyz). I want exact value in querystring "abc+xyz"

Note: href value cannot be changed

Any help will be appreciated

Thank You.

4 Answers 4

7

This will Server.UrlDecode for you:

Request.QueryString["name"] // "abc xyz"

Option 1) You can re-encode

Server.UrlEncode(Request.QueryString["name"]); // "abc+xyz"

or get the raw query data

Request.Url.Query // "?name=abc+xyz"

Option 2) Then parse the value

Request.Url.Query.Substring(Request.Url.Query.IndexOf("name=") + 5) // "abc+xyz"
Sign up to request clarification or add additional context in comments.

Comments

1

ASP.net will decode the query string for your. you can get the raw query string and parse it yourself if you want.

Comments

0

Try webform1.aspx?name=abc%2Bxyz

1 Comment

@Faizal In that case, if you don't expect space in your name query parameter, just replace space with +.
0

Use this :
Request.QueryString["name"].Replace(" ","+");
// Refer below link for more info
http://runtingsproper.blogspot.in/2009/10/why-aspnet-accidentally-corrupts-your.html

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.