Solved

Retrieve Multiple Checkbox values on Server-side

Posted on 2004-09-14
4
390 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

777 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