Solved

Retrieve Multiple Checkbox values on Server-side

Posted on 2004-09-14
4
392 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
[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
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

749 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