Solved

Retrieve Multiple Checkbox values on Server-side

Posted on 2004-09-14
4
388 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility

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

   -Payal :)
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Pass selected value to a function 14 30
Replacing HTML tags in Textarea/Textbox 5 20
asp.net mvc5 3 35
Duplicate a row 2 28
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

762 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

15 Experts available now in Live!

Get 1:1 Help Now