Quick ASP preference question

DJFuji

Diamond Member
Oct 18, 1999
3,643
1
76
Working on some mods for a legacy app that involves "classic" ASP 3.0. Now I really apprecate .NET's infrastructure.

Anyhow, while I was coding I started to wonder if other people code submit buttons differently. Whenever I have a page with multiple submit buttons, I name them differently and then do a

if request.form("submitbtn") <> "" then

line of code to tell which button was pressed. I got to thinking that maybe it would be easier if I named all the buttons the same and then just made the values different and queried the request.form("genericbuttonname") on what its value was. (kinda like when you have a check box column)

Do you guys do it like that or the way I do it? Is one method better than another or does it just come down to preference?
 

SALvation

Senior member
Apr 10, 2001
964
0
0
You can give each submit button a different value and then check to see which submit button was checked:

if request.form("submit1") <> "" then

elseif request.form("submit2") <> "" then

end if

That should work.
 

torpid

Lifer
Sep 14, 2003
11,631
11
76
Originally posted by: SALvation
You can give each submit button a different value and then check to see which submit button was checked:

if request.form("submit1") <> "" then

elseif request.form("submit2") <> "" then

end if

That should work.

No. If you give them different values, then the value is different, not the key in request.form. If they all have the same name, you'd do request.form("name") and check the value.

To answer the question, I prefer the same name for submit generally. There are some instances where it doesn't work out well to do it though.
 

DJFuji

Diamond Member
Oct 18, 1999
3,643
1
76
thanks torpid that's kinda what i was wondering. What situations have you run into where it doesnt work right?
 

torpid

Lifer
Sep 14, 2003
11,631
11
76
Originally posted by: DJFuji
thanks torpid that's kinda what i was wondering. What situations have you run into where it doesnt work right?

Well, it still "works" but it doesn't always suit your needs. A submit button's text is the same as the value. So if you need two buttons called "Go" on the same form you will have to use a different technique to figure out which was clicked.