Question

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.

Was it helpful?

Solution 2

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.

OTHER TIPS

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

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

You do not need the quotation marks in your querystring.

It should read

register.aspx?id=jSmith

You should look for

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

the \ is escaping the extra "

or you could perform a replace to remove the extra "

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top