Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 326951
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T09:21:24+00:00 2026-05-12T09:21:24+00:00

I am searching for control names using Request.Form. Of course I know you can

  • 0

I am searching for control names using Request.Form.

Of course I know you can can iterate around all values using AllKeys, and you can do Form[“controlName”] as well.

However some of my control names are dynamic and it would be useful to be able to do stuff like:

1)Getting a subset of controls in the collection whos name start with a certain prefix
2) Search for control names that match a pattern, as you would do with a regular expression.

But there is no way I can see to do stuff like this.

N.B I know how to use FindControl for ASP.NET controls but these are standard HTML.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T09:21:25+00:00Added an answer on May 12, 2026 at 9:21 am

    If you are using C#3 you can use LINQ and extension methods to achieve this in a very nice way. First you need to create an extension method devised by Bryan Watts in this thread:

    public static IEnumerable<KeyValuePair<string, string>> ToPairs(this NameValueCollection collection)
    {
        if (collection == null)
        {
            throw new ArgumentNullException("collection");
        }
        return collection.Cast<string>().Select(key => new KeyValuePair<string, string>(key, collection[key]));
    }
    

    Now, say you had a form like this:

    <form id="form1" runat="server">
    <div>
        <input type="text" name="XXX_Name" value="Harold Pinter" />
        <input type="text" name="XXX_Email" value="harold@example.com" />
        <input type="text" name="XXX_Phone" value="1234 5454 5454" />
    
        <input type="text" name="YYY_Name" value="AN. Other" />
        <input type="text" name="YYY_Email" value="another@example.com" />
        <input type="text" name="YYY_Phone" value="8383 3434 3434" />
    
        <input type="submit" value="submit button" />
    </div>
    </form>
    

    You could do this in your codebehind:

    protected void Page_Load(object sender, EventArgs e)
    {
        var data = Request.Form.ToPairs().Where(k => k.Key.StartsWith("XXX_"));
    
        foreach (var item in data)
        {
            Response.Write(String.Format("{0} = '{1}', ", item.Key, item.Value));
        }
    }
    

    Which would output:

    XXX_Name = 'Harold Pinter'
    XXX_Email = 'harold@example.com'
    XXX_Phone = '1234 5454 5454'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I post a form using dojo.xhrPost , I get all the fields in
I am searching a grid view using control parameters, but in my code I
Searching with '[Delphi] source control' didn't return much, so here goes: For those of
I'm searching for a button control that will AutoSize its image. Normal button controls
Searching around I haven't found any recent answers to this question. The other answers
Searching for values that uses the same value Example SELECT Name, UnitPrice, Quantity, Color
searching around trying to find a way to add index on suffix of a
Salvete! Whilst searching for a quality, free asp.net/ajax upload control, I found NeatUpload. I
Good day, I have been searching for a way to format output using writeline/write
I Have a Strongly typed user control which i use for Searching a certain

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.