Solved

Retrieve Multiple Checkbox values on Server-side

Posted on 2004-09-14
4
389 Views
Last Modified: 2012-06-27
Hi,

      I have a .aspx web page with html and C# server code inline.

      I have a table which is populater from database and a checkbox is rendered with it on every row.

      I want the values of all checkboxes that were checked on the server side.

      I read on some web page that       'Request["chkboxcontrolname"] '  will give me a string with comma separated values of all Checked checkboxes.

      I also tried  'Request.Form["controlname"]' . But didnt get anything. :(

      But i am not able to catch it with this method.

      Any ideas?

    - Payal
0
Comment
Question by:payal1711
  • 2
  • 2
4 Comments
 
LVL 8

Accepted Solution

by:
shovavnik earned 50 total points
ID: 12062070
Both of those should work.

However, you need to make sure your checkboxes have a "name" attribute that is identical.

You can set the name attribute manually, in the aspx page, just by adding it:

<asp:Checkbox ID="whatever" name="checkboxes" runat="server"></asp:Checkbox>

Request.Form[ "checkboxes" ]
0
 
LVL 1

Author Comment

by:payal1711
ID: 12066690
hey shovavnik,

    Thank you so much. How did you know exactly taht I was missing the 'name' field. I thought that 'id' field was enough. It never occured to me taht name was mandatory for these controls.

    Thanks again,
   -Payal
0
 
LVL 8

Expert Comment

by:shovavnik
ID: 12084346
Thanks for the points, Payal.

You need to keep in mind that the "id" and "name" attributes server different purposes.

"id" is intended to be unique.  No two controls should have the same id.  In fact, if you enter the same if for two controls, visual studio will underline those controls and may not even compile.

"name" is a grouping attribute.  It's intended to allow multuple controls to be treated together.  This is what radio boxes use, for example, to determine grouping.  (GroupName on WebControls that support the attribute render it as "name" in html.)

In javascript, you have two different functions (cross-browser) that exemplify this difference:

document.getElementById retrieves a single element on the page that has the requested id.
document.getElementsByName retrieves all elements on the page that have the requested name.

Note that the functions are named in singular and plural, respectively, to clarify their purposes.

Hope that clears things up for you.
0
 
LVL 1

Author Comment

by:payal1711
ID: 12086238

   Thanks for the short tutorial. It was indeed of great help. I wont forget this now.

   -Payal :)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
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…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

867 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

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now