get all the form fields in a form

M

Mr. SweatyFinger

I'll never understand this

for each ?? in request.form.items
response.write ??

next

what the heck is ?? and how do yo dim it?
can it be any name?
 
G

Gaurav Vaish \(MasterGaurav\)

I'll never understand this
for each ?? in request.form.items
response.write ??

next

what the heck is ?? and how do yo dim it?
can it be any name?

Dim entryName as String

for each entryName in Request.Form
Response.Write("Name: " & entryName & "<br/>")
Response.Write("Value: " & Request.Form[entryName] & "<br/>")
next


HTH


--
Happy Hacking,
Gaurav Vaish | www.mastergaurav.com
www.edujini-labs.com
http://eduzine.edujinionline.com
-----------------------------------------
 
G

Guest

Hi Mr.,

foreach (string key in Request.Form.AllKeys)
{
Response.Write(key);
Response.Write("=");
Response.Write(Request.Form[key]);
Response.Write("<br>");
}
 
G

Guest

For Each makes a loop through items in collection of Request.Form,
and item is a string, specifying the name of the form field that's being
sent

Dim Item as String

For Each Item in Request.Form
Response.Write Item
Response.Write Request.Form(Item)
Next
 
M

Mark Rae

I know off topic,

Why off-topic...? This is an ASP.NET newsgroup after all... :)
anyone here know of a C# equivelent?

foreach (string strKey in Request.Form)
{
Response.Write(strKey);
Response.Write "=";
Response.Write(Request.Form[strKey].ToString());
Response.Write("<br />");
}
 
G

Gary

I know off topic,
Why off-topic...? This is an ASP.NET newsgroup after all... :)


Oh yeah :)

anyone here know of a C# equivelent?

foreach (string strKey in Request.Form)
{
Response.Write(strKey);
Response.Write "=";
Response.Write(Request.Form[strKey].ToString());
Response.Write("<br />");
}


Cheers dude.

G.
 
M

Mr. SweatyFinger

That's what I don't get.
if item can be named anything...

how does the procedure know that I want items, as opposed to any of the
other properties?
 
G

Guest

The collection of Request.Form has only item names and you can't get other
properties.

It is the same with any other collection, for example, when you have an
array of strings

Dim lines As String()
Dim line As String
For Each line In lines
Next

This code enumerates the strings in array.
 
M

Mr. SweatyFinger

well, given a collection, how are you supposed to know which is the default
property??
 
G

Guest

What do you mean by default property of collection?

According to MSDN:

Request.Form gets a collection of form variables. Its property value is
a NameValueCollection representing a collection of form variables. And
NameValueCollection Class represents a sorted collection of associated
String keys and String values that can be accessed either with the key
or with the index.

In other words, Request.Form is a collection of strings {"aa", "bb",
"cc"...}.

"aa" is a string which represent a name of a form variable

No properties.
 
M

Mr. SweatyFinger

what I mean is there are several properties of a form field

when i loop through the "items", how am I supposed to know which of the
properties i am looping through

for instance, request.form has items, keys, allkeys, count.

why doesn't this pull in the keys, rather than the items.

For Each entryName In Request.Form

Response.Write("Name: " & entryName & "<br/>")

Response.Write("Value: " & Request.Form(entryName) & "<br/>")

Next
 
J

Juan T. Llibre

Maybe the OP was referring to the default order of retrieval ?

When you do a call to the default Request collection,
each of the sub collections are searched in the following order:

1. QueryString
2. Form
3. Cookies
4. ClientCertificates
5. ServerVariables

The process stops when the first match is found.

Unfortunately, if there's same-name items in two or more sub collections,
you aren't guaranteed to receive the data you're looking for.

That's why you shouldn't use : Request("name")

You should use Request.Form("name") or Request.Cookies("name")
or Request.QueryString("name"), etc., always specifying the sub collection
you want to retrieve data from.
 
G

Guest

Well, the question was about Request.Form as I see. Anyway, you're
right, it has to be more detailed
 
G

Gaurav Vaish \(www.edujini-labs.com\)

well, given a collection, how are you supposed to know which is the
default
property??

I have a small suggestion for you.
Go through the basics of .Net Framework, VB.Net and Collections-API before
starting with ASP.Net

And I'm damn serious. You may really mess up your ASP.Net learning
otherwise.


--
Happy Hacking,
Gaurav Vaish | www.mastergaurav.com
www.edujini-labs.com
http://eduzine.edujini-labs.com
-----------------------------------------
 
G

Guest

what I mean is there are several properties of a form field

when i loop through the "items", how am I supposed to know which of the
properties i am looping through

for instance, request.form has items, keys, allkeys, count.

why doesn't this pull in the keys, rather than the items.

For Each entryName In Request.Form

Response.Write("Name: " & entryName & "<br/>")

Response.Write("Value: " & Request.Form(entryName) & "<br/>")

Next

For Each...Next loop is designed for collections and arrays only. It
means you could loop through elements of a collection or array only.

You can't loop through Count property because it's not a collection.

You can loop through Request.Form, Request.Form.Keys or
Request.Form.AllKeys collections.

For Each entryName In Request.Form.Keys
Response.Write("Name: " & entryName & "<br/>")
Response.Write("Value: " & Request.Form(entryName) & "<br/>")
Next

or

Dim loop1 As Integer
Dim arr1() As String
arr1 = Request.Form.AllKeys
For loop1 = 0 To arr1.GetUpperBound(0)
Response.Write("Form: " & arr1(loop1) & "<br>")
Next loop1
 
M

Mr. SweatyFinger

so how do you look at the screen and see what is a collection and what is
not?

what tells you? is there a certain color icon?
 

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

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,177
Latest member
OrderGlucea
Top