Solved

Retrieve Multiple Checkbox values on Server-side

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

691 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