Solved

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

Posted on 2012-12-21
5
489 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Request.Form.GetValues("field") does the trick. It returns type String() with multiple values.

Thanks
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
This video discusses moving either the default database or any database to a new volume.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

771 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

11 Experts available now in Live!

Get 1:1 Help Now