Solved

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

Posted on 2012-12-21
5
507 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

680 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