Reputation: 1227
I have a parameter:
string custName = "";
custName = AddressDT.Rows[0]["first_name"].ToString() + " " + AddressDT.Rows[0]["last_name"].ToString();
I am performing my Response.Redirect
Response.Redirect("~/Account/EmailError.aspx?parm1=custName");
and I am retrieving the parameter value:
custName = Request.QueryString["parm1"];
when I run debug: ... custName = "custName"
what am I doing wrong? I have done this before with no issue.
Upvotes: 0
Views: 1202
Reputation: 62260
If you already know that QueryString value is string, you need to use UrlEncode.
In addition, you want to use String.Format
as much as possible for good design practice instead of +.
string custName = String.Format("{0} {1}",
AddressDT.Rows[0]["first_name"].ToString(),
AddressDT.Rows[0]["last_name"].ToString());
string url = String.Format("~/Account/EmailError.aspx?parm1={0}",
Server.UrlEncode(custName));
Response.Redirect(url);
Upvotes: 0
Reputation: 15860
That is because you're using a String Constant as the value for the parameter.
Response.Redirect("~/Account/EmailError.aspx?parm1=custName");
That would always cause the URL to be set with the string custName
.
Try using the variable name as:
Response.Redirect("~/Account/EmailError.aspx?parm1=" + custName);
Now the variable would be appended to the request.
Now when you'll run the code, it would produce the value in the Variable and you'll get the code running fine.
Always remember to finish the string and then adding the variable values. Everything inside the double qoutes is considered to be a string and not a variable name or a keyword.
Upvotes: 2
Reputation: 12805
Your Response.Redirect
is passing the string "custName", not the value of the variable.
This will fix it for you:
Response.Redirect("~/Account/EmailError.aspx?param1=" + custName);
Upvotes: 2