Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7810797
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T03:55:31+00:00 2026-06-02T03:55:31+00:00

Within a web form I am dynamically creating a series of chekboxes that are

  • 0

Within a web form I am dynamically creating a series of chekboxes that are added to an asp:placeholder

//Generates the List of Entities that may be shared
        protected void GenerateEntityList(string agencyId, string agencyName)
        {
            var selectedAgency = UserFactory.GetAgencyAndSharedDataById(Convert.ToInt64(agencyId));

            entityContainer.Controls.Clear();

            //builds the entity list based upon entities in DB
            var currentEntities = UserFactory.GetEntityList();
            //add checkboxes
            entityContainer.Controls.Add(new LiteralControl("<input type='checkbox' id='selectAllCB' value='All'>Select All<br/><br/>"));
            foreach (var item in currentEntities)
            {
                CheckBox entityCheckBox = new CheckBox();
                int currentItem = item.EntityTypeId.GetValueOrDefault(0);
                entityCheckBox.Text = item.EntityName.ToString();

                entityCheckBox.CssClass = "am_Checkbox";
                entityContainer.Controls.Add(entityCheckBox);
                entityContainer.Controls.Add(new LiteralControl("<br/><br/>"));

                //mark checkboxes as checked if currently stored in the database
                if (selectedAgency.FirstOrDefault().SecurityDataShares != null && selectedAgency.FirstOrDefault().SecurityDataShares.Count > 0)
                {
                    foreach (var ce in selectedAgency.FirstOrDefault().SecurityDataShares)
                    {
                        if (ce.EntityId == item.EntityId)
                        {
                            entityCheckBox.Checked = true;
                        }
                    }
                }
            }

Once created the user has the ability to make or remove selections. When clicking update I would like to return/collect the values from the checkboxes so that I may insert them back into the db.

//get the text value of every checkbox 
protected void updateEnties()
{
    string receivingAgency = ReceivingAgencyID;
    long contributingAgency = QueryID;

    List<string> cbValues = new List<string>();
    foreach (CheckBox currentItem in entityContainer.Controls)
    {
        cbValues.Add(currentItem.Text);
    }
}

However when I attempt to iterate over the collection I am not getting anything back which leads me to believe either I am calling the control incorrectly or it is being destroyed due to the postback.
Instead of writing these elements to a place holder should I use another controls like a Listbox control?

Can someone please provide me with some guidance on how I can retrieving the checkbox values?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T03:55:34+00:00Added an answer on June 2, 2026 at 3:55 am

    There are two schools of thought; one, that you need to recreate the control hierarchy that was made for the initial view so that the page can restore the view state and form values into the control tree, or two, that you can go with a low tech solution and simply get the values from the form collection.

    I personally, like option two, and it’s relatively easy to deal with, and since it looks like you’re already manually creating the HTML with LiteralControl. Simply provide a name attribute that is shared among your manually created input tags (example shown here for brevity, this is probably not what you will do):

    entityContainer.Controls.Add(new LiteralControl("<input type='checkbox' name='mySharedName' />");
    

    Then, to get the values it is as simple as this:

     var selectedValues = Request.Form["mySharedName"];
     // This is now a comma separated list of values that was checked
    

    Then you dont have to worry about the control tree state.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Obviously I know how to do this with DefaultButtons within an ASP.NET web form.
Within an asp.net web form I would like to add values back to a
I have an ASP.NET web form that has a container usercontrol that hosts several
I have a complex input form within a PHP based web application. To structure
Within my web application, I was thinking of creating a pop-up screen of a
I have a Web page within my application that needs to call a web
I am creating a tool with which to edit web pages within a CMS.
I'm trying to make a web page that only has content within the page
Within my web application I am using some custom validation for my form fields.
Within a web form I have the following jQuery setup to call a method

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.