Solved

Request.Form: see difference between multiple form fields with the same name

Posted on 2012-12-21
5
493 Views
Last Modified: 2012-12-21
Does the Asp.Net Request.Form offer any way to see the difference between

<form method="post">
<input type="hidden" name="field" value="a" />
<input type="hidden" name="field" value="a" />
<input type="hidden" name="field" value="a" />
</form>

and

<form method="post">
<input type="hidden" name="field" value="a,a,a" />
</form>


For example is there a way to count how many fields with name="field" have been submitted?

(in Classic ASP that is possible, but I can not find a way to do it in Asp.Net)
0
Comment
Question by:sybe
5 Comments
 
LVL 39

Accepted Solution

by:
Pratima Pharande earned 500 total points
ID: 38712362
Request.Form returns NameValueCollection. GetValues is a NameValueCollection class method which gives us the requested result.

you can store this resukt and do the manipulation as per your requirement
0
 
LVL 2

Expert Comment

by:tempor2001
ID: 38712367
Hi,

you can go trough Request.Form.AllKeys list and see if there multiple "field" keys found.

dim fieldCount  as integer = 0
    For Each key As String In Request.Form.AllKeys
      if key = "field" then fieldCount= fieldCount+1
    Next

Open in new window

0
 
LVL 25

Expert Comment

by:Rouchie
ID: 38712371
In ASP.Net all form fields need to have a unique name so that they can be differentiated from one another.  Are you posting to .Net from classic ASP?

You can enumerate like pratima_mcs states.  This is much more easy if your posting form is .Net to begin with.  A pseudo code example would be something like...

For each form control in someContainer
   If control type is input Then
      if control.uniqueID ends with 'field' Then
          controlCount += 1
      End if
   End If
End For

Open in new window

0
 
LVL 2

Expert Comment

by:tempor2001
ID: 38712376
ignore my comment, pratima_mcs solution is much more elegant :) and require only 1 line of code ;)
0
 
LVL 28

Author Closing Comment

by:sybe
ID: 38712397
Request.Form.GetValues("field") does the trick. It returns type String() with multiple values.

Thanks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now