Skip to content Skip to sidebar Skip to footer

Count Html Form Inputs With Name Prefix From Asp.net Code Behind

I've been searching for a while for something similar with no luck. This is what I have:

Solution 1:

var categoryInputKeys = Request.Form.AllKeys.Where(x=> x.StartsWith("category_")).ToList();

after fetching keys you can use them with like that

Request.Form[categoryInputKeys[0]]

Edit: For just counting them that will be enough;

var categoryInputCount = Request.Form.AllKeys.Where(x=>x.StartsWith("category_")).ToList().Count;

Solution 2:

Add attribute runat="server" then you can get access controls in code behind

Post a Comment for "Count Html Form Inputs With Name Prefix From Asp.net Code Behind"