Solved

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

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

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
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.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

803 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