Reputation: 46312
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.
Upvotes: 1
Views: 1104
Reputation: 68
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
Upvotes: 1
Reputation: 7765
You should look for
if (qString == "\"jSmith\"")
the \
is escaping the extra "
or you could perform a replace to remove the extra "
Upvotes: 1
Reputation: 4854
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
Upvotes: 2
Reputation: 1707
You do not need the quotation marks in your querystring.
It should read
register.aspx?id=jSmith
Upvotes: 1
Reputation: 60664
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.
Upvotes: 1
Reputation: 6947
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
Upvotes: 1