Reputation: 128
I am trying to request a Query String and insert the value into a variable in C#. I have tried three different way: parsing, converting, and assigning an intermediate string to then be converted to a int. The variable is then put into a database. The problem is that every request comes results null when to URL is displaying the proper ID.
Here is the post back:
<%#"../ShoppingCart/AddToCart.aspx?Id="+Eval("ProdID")%>'/>
Here is the request:
//receives the query string (as a string and converts to an int) sent by the selected item to be added to the cart
int productID = Int32.Parse(Request.QueryString["ProdID"]);
Here is the URL displaying the correct ID being passed:
localhost:59200/ShoppingCart/AddToCart.aspx?Id=1
When I place a breakpoint to check the query string value, I claims to have the proper ID.Yet after all of that, I still get a null request. Can you not convert a request to a variable?
Upvotes: 1
Views: 2135
Reputation: 2667
//receives the query string (as a string and converts to an int) sent by the selected item to be added to the cart
int productID = Int32.Parse(Request.QueryString["Id"]);
Upvotes: 0
Reputation: 3752
The name of your query string is "Id", not "ProdID" (which would be the name of the local variable).
Upvotes: 4