1

I have the following page querystring:

 register.aspx?id="jSmith"

I have the following code to retrieve the value of ID

    string qString = string.IsNullOrEmpty(Request.QueryString["id"]) ? string.Empty : HttpUtility.UrlDecode(Request.QueryString["id"]);

When I view the value of qString I get something like

    "\"jSmith\""

so when I do the following:

     if (qString == "jSmith")
     {
        ........

     }

it does not not execute the if condition. What do I need to do s that it does not have the quotes.

6 Answers 6

2

The code is correct. The problem is that you are passing to the page "jSmith" with the double quotes as part of the string. Try invoke the page this way

register.aspx?id=jSmith
Sign up to request clarification or add additional context in comments.

Comments

1

That is because the correct way to give the path in this case would be register.aspx?id=jSmith, without the quotes. If you need spaces, or other special characters, in your ID, these should be URL encoded (and will be decoded by your code), but not enclosed in quotes.

For example, if your id was the string john smith, the URL would become register.aspx?id=john+smith, since + is the URL encoding of a space.

Comments

1

You don't need to put quotes around values in querystring, by definition they're all strings...

Your querystring should look like :

register.aspx?id=jSmith

Comments

1

You do not need the quotation marks in your querystring.

It should read

register.aspx?id=jSmith

Comments

1

You should look for

if (qString == "\"jSmith\"")

the \ is escaping the extra "

or you could perform a replace to remove the extra "

Comments

1

use

 Response.Redirect("Qstring.aspx?name= smith");

and on the page Qstring.aspx load event

 string s=Request.QueryString["name"].ToString();

gives u "smith" in s variable

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.