0

I am facing one problem while storing a querystring value in a variable. My url is something like shown below:

http://localhost:1372/testapp/default.aspx?Search=%family%

Below is what I tried:

string result = Request.QueryString["Search"].ToString();

When I tried to save the querystring search in variable its taking value as �mily% .

How can I get value of search parameter as family?

Thanks in advance.

1
  • 1
    Where does that query string come from? It is clearly wrong ... you need to UrlEncode the parameter. Commented Jun 6, 2014 at 9:38

2 Answers 2

1

The query string parameters have to get URL-encoded. The problem ist th % character which is used for URL encoding, so it has to get encoded itself.

'%' becomes '%25'

Which means, the whole URL becomes:

http://localhost:1372/testapp/default.aspx?Search=%25family%25

your can use HttpUtitlity.UrlEncode

Sign up to request clarification or add additional context in comments.

1 Comment

I tried this but its giving me value as '%ef%bf%bdmily%25'
1

In Parent Page Encode query string this way

public static sting Encode(string sData)
{
return HttpUtility.UrlEncode(sData);
}

Now pass this encoded query string to your parent page & on Parent page decode that query string by following function. I assume that encoded query string name is sData & its passed from parent page to child page

public static string Decode()
{
string dSData = HttpUtility.UrlDecode(Request.QueryString["sData"].ToString());
return dsData;
}

I think you have idea about how to pass query string from parent to child page

try this solution for more .

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.