Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2012-12-21
5
Medium Priority
?
529 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 39

Accepted Solution

by:
Pratima Pharande earned 2000 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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

596 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