Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Request.Form("....").Count doent work in ASP.Net 2

Status
Not open for further replies.

eramgarden

Programmer
Aug 27, 2003
279
US
Howcome this isnt working in ASP.Net??

count=Request.Form("chk_sections").Count

Request.Form("chk_sections") has values (A, B, C, D). They are checkboxes that are checked in the previous page.

I get an error : 'Count' is not a member of 'String'.

Then how can I count how many check boxes were checked??


 
Are you submitting to another page? Why not process in the same page code behind event handler?
 
submitting to another page...

I'm upgrading ASP to ASP.Net.

Dont want to change too many things with it now...just like to upgrade and get it working as is now...

so howcome that doesnt work??
 
Hi eramgarden

From what I can see - in ASP.NET Request.Form["blah"] returns the value of the element blah from the form - in a string. It doesn't return all form elements in an array.

If you want to get a count of all form elements in Request.Form - you may want to try
Request.Form.Count
Request.Form.AllKeys.Length

Hope that helps!

Craftor

:cool:
 
ok, getting closer... thank you guys for helping me out..I'm new to .Net

If i do :
Request.Form.Count
Request.Form.AllKeys.Length

Then I will always get 2 as the count...i think becuase i have 2 forms in the page...

This is the senario: I have to say, i have inherited this code...

Page1.aspx : There are 5 checkboxes. I check 3 of them.. The check boxes are in a form element.click save, goes to Page2.aspx

[/b]page2.aspx In the ASP page, it was doing
count=Request.Form("chk_sections").Count
To see how many check boxes are checked and then went about it's business..

in ASP.Net, Craftor, you are right about what you said But now my question is, how can i get the count of how many checkboxes were checked..

I did this:
for each item in Request.Form("chk_sections")
count = count +1
next

But if request.form("chk_sections") has this value (AB,CD,EFG)...it gives the count of 7..it actually counts A,B,C,D...but in this case I want count of 3 (AB, CD,EFG)

I found a website to use checkbox class in .Net but since i'm new and just want to upgrade this code, is there an easier way to do this??
 
Ok, Thanks guys for pointing me to the right direction:

I found the answer:
If I do this , i will get the count of how many check boxes were checked:

count = Request.Form.GetValues("chk_sections").Length
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top