1

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?

2 Answers 2

4

The name of your query string is "Id", not "ProdID" (which would be the name of the local variable).

Sign up to request clarification or add additional context in comments.

3 Comments

Not the name of the local variable but rather the name of the dictionary key for the QueryString dictionary.
Well, in the second code snippet, it's the dictionary key... but that's where it's wrong. The first code snippet, since it's in Eval, it would be the name of some sort of variable.
You bet. Make sure you mark an answer if your problem was solved.
0
//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"]);

1 Comment

Thanks for the help. That solved it. I had implemented another query string in my project in the very same way I asked my question about, but it functioned like it should have so when this one did not I was lost. i guess the first time was a bit of a fluke. Thanks again.

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.