Click to See Complete Forum and Search --> : Error with QueryString. Help please!


iKhristosi
June 17th, 2008, 12:20 PM
I have a form that has 3 submit buttons. They all call the same .asp file, but different information is processed depending on which button is pressed. Is there a way for me to check which button was pressed using the QueryString?
Here's the code I'm currently trying, but I am getting an error on the server:


On Error Resume Next

For each item in Request.QueryString()

If item = "submitIt" Then
ObjSendMail.To = Request.QueryString("SupEmail")
ObjSendMail.Subject = "foobar"
ObjSendMail.From = Request.QueryString("ReqEmail")
body = "blah"
ElseIf item = "approveIt" Then
ObjSendMail.To = "Christian.Grise@usa.dupont.com
ObjSendMail.Subject = "bar"
ObjSendMail.Cc = Request.QueryString("ReqEmail")
ObjSendMail.From = Request.QueryString("SupEmail")
body = "blahdy"
ElseIf item = "denyIt" Then
ObjSendMail.To = Request.QueryString("ReqEmail")
ObjSendMail.Subject = "foo"
ObjSendMail.From = Request.QueryString("SupEmail")
body = "blah blah"
End If
Next


Any help will be greatly appreciated. Thank you in advance.

Christian

hspc
June 17th, 2008, 12:30 PM
Do you use asp or asp.net ?
What is the server error?
are you sure that you made the form action = GET not POST ?
Why do you use foreach? whay don't just explicitly check for the key name that you need?

iKhristosi
June 17th, 2008, 12:35 PM
I think I'm just using asp.
The server error is the generic, "There may be an error in your code" type of error.
I'm positive the form is GET.
I tried explicitly checking for the key name. That also didnt work.

hspc
June 17th, 2008, 01:06 PM
If you attach a complete asp page that has a problem, this will make it easier to trace. Maybe the problem is with the HTML. Can you post the asp page after removing any irrelevant code ?

Alsvha
June 17th, 2008, 02:02 PM
Been a long time since I've done any regular asp, however, usually a querystring item is made up of a key/value pair - for example:
example.com?someKey=value
So you can request "Request.QueryString("someKey") and get "value" returned.

I am not sure it is possible to iterate via a for each over a querystring's items the way you do?
Perhaps it is in asp?

What happens if you try to request the querystring on your three buttons form names after being submitted?

iKhristosi
June 17th, 2008, 02:09 PM
I believe the problem is when I check for the other 2 buttons. Since they were not clicked, they are not sent to the QueryString and I believe that is where the error is occuring.

hspc
June 17th, 2008, 02:49 PM
Removing On Error Resume Next can help you identify the source of the error. This is a really bad statement.
Also check the line number in the server error.

Alsvha
June 18th, 2008, 12:28 AM
I believe the problem is when I check for the other 2 buttons. Since they were not clicked, they are not sent to the QueryString and I believe that is where the error is occuring.

My immediately thought is that only the button which was the one triggered should be the one with a value. That is how you know which button was used.

But I'm still unsure whether you do do "for each item" in a Querystring collection and then ask whether the item equals a string, when I think the item should be a key/value collection.
I'd think you have to iterate over each key, and then ask for that keys value.