LOOP through an ASP form's pages (not ASP.NET - ASP classic)

D

David A. Beck

Curt,

In the COM object, using the scripting context, there is no .Items
collection in the Request Object.

Dab
 
S

Scott McNair

I found a great article and use the techniques to loop through a form
and get all the controls in ASP.NET "Looping Through Controls in
ASP.NET"
http://www.extremeexperts.com/Net/Articles/LoopingthroughControls.aspx

I want to do the same thing in a VB COM control for classic ASP. Can
anyone point me to an article that shows me how to get the control
type, etc?

If you're calling the form thru <form method=post>, it would be

For Each Item In Request.Form
Response.Write Item & ": " & Request(Item) & "<br>"
Next

If it's just a generic <form> object,

For Each Item In Request.QueryString
Response.Write Item & ": " & Request(Item) & "<br>"
Next
 
E

Evertjan.

Scott McNair wrote on 12 apr 2004 in
microsoft.public.inetserver.asp.general:
For Each Item In Request.Form
Response.Write Item & ": " & Request(Item) & "<br>"
Next

This will not be correct if there is also a querystring

Use:

For Each Item In Request.Form
Response.Write Item & ": " & Request.Form(Item) & "<br>"
Next
 
D

David A. Beck

Scott:

Could you send a small page with this code in it, because I'm not getting
any joy using it in mime. Thanks.

Dab
 
M

[MSFT]

Hi David,

In ScriptingContext, IRequest interface also have FORM collection. You may
take a look at following MSDN articles:

Request.Form Collection
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/iissdk/iis/
ref_vbom_reqocf.asp

Request Object
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/iissdk/iis/
ref_vbom_reqo.asp?frame=true

IScriptingContext::get_Request
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/iissdk/iis/
ref_biobj_cppiscget_rqst.asp

IScriptingContext C++ Interface
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/iissdk/iis/
ref_biobj_cppisc.asp

Accessing ASP Built-In Objects from Components
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/iissdk/iis/
accessingaspbuiltinobjectsfromcomponents.asp

In the post you sent in asp.components, I may misunderstand your
description. I think above information should be what you are looking for.
Hope them help.

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
S

Scott McNair

If you're calling the form thru <form method=post>, it would be

For Each Item In Request.Form
Response.Write Item & ": " & Request(Item) & "<br>"
Next

If it's just a generic <form> object,

For Each Item In Request.QueryString
Response.Write Item & ": " & Request(Item) & "<br>"
Next

Just as a side note, I've found this technique very useful for
populating a table on a database - as long as the field names in the
table are the same as the form object names, it's as easy as:

[set up your connection, recordset, etc]
RS.AddNew
For Each Item In Request.Form
RS(Item) = Request.Form(Item)
Next
RS.Update

I find it's a good way to populate a table with a kajillion different
fields from a table with a kajillion different fields, in essentially 3
lines of code.
 
B

Bob Barrows [MVP]

Scott said:
Just as a side note, I've found this technique very useful for
populating a table on a database - as long as the field names in the
table are the same as the form object names,

And the datatypes cooperate ....
it's as easy as:
[set up your connection, recordset, etc]
RS.AddNew
For Each Item In Request.Form
RS(Item) = Request.Form(Item)
Next
RS.Update

I find it's a good way to populate a table with a kajillion different
fields from a table with a kajillion different fields, in essentially
3 lines of code.

It's great for the coder - not so good for the application performance and
scalability. Cursors should not be used for data maintenance. How about
this:

sSQLi = "INSERT INTO table ("
sSQLv = " VALUES("
for each Item In Request.Form
sSQLi = sSQLi & Item & ","
'you will need logic here to handle various datatypes
Select Case datatype
Case "Text"
sSQLv= sSQLv & "'" & Replace(Request.Form(Item),"'","''") & "',"
Case "Number"
sSQLv= sSQLv & Replace(Request.Form(Item),"'","''") & ","
Case "Date"
sSQLv= sSQLv & "#" & Replace(Request.Form(Item),"'","''") & "#,"
Next
'get rid of the trailing commas
sSQLi = Left(sSQLi,len(sSQLi) - 1) & ")"
sSQLv = Left(sSQLv,len(sSQLv)-1) & ")"
sSQL = sSQLi & sSQLv
Response.write sSQL
conn.Execute ,,129

Now you've had to write a little more code, but, now you've handled all the
chores that ADO needs to do behind the scenes anyways when updating a
recordset. Pluse you've eliminated the need to open an expensive updatable
cursor.

Bob Barrows
 
S

Scott McNair

Now you've had to write a little more code, but, now you've handled
all the chores that ADO needs to do behind the scenes anyways when
updating a recordset. Pluse you've eliminated the need to open an
expensive updatable cursor.

Good call.
 
S

Scott McNair

[snip]
'you will need logic here to handle various datatypes

One way would be to name your form objects so that the first three
letters describe the data type... e.g. txtName, numAge, datRegistered,
then do

Select Case Left(Request.Form(Item),3)
Case "txt"
sSQLv = sSQLv & "'" & Right(Request.Form(Item),Len(Request.Form
(Item))-3) &"',"
Case "num"
[etc]
Case "dat"
[etc]
End Select
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,835
Latest member
KetoRushACVBuy

Latest Threads

Top