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 6791055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:48:00+00:00 2026-05-26T17:48:00+00:00

I have a very dynamic web app that is dynamically created controls at run-time.

  • 0

I have a very dynamic web app that is dynamically created controls at run-time.

Here is the first needed part of my code to solve my issue.

This is in a for loop, essentially it creates multiple checkbox’s with ID’s and event handlers.

// All I am doing here is incrementing our session counter so we can increment our ID
int id = Convert.ToInt32(Session["id"]);
id++;
Session["id"] = id;

// Now I create my checkbox
chkDynamic = new CheckBox();
chkDynamic.Text = "hey";
string chk = "chk" + id.ToString();

chkDynamic.ID = chk;
chkDynamic.CheckedChanged += new EventHandler(chkDynamic_CheckedChanged);
Panel1.Controls.Add(chkDynamic);

This next section is our custom even handler

protected void chkDynamic_CheckedChanged(object sender, EventArgs e)
    {

        if (((CheckBox)sender).Checked)
            Response.Write("you checked the checkbox :" + this.chkDynamic.ID);
        else
            Response.Write("checkbox is not checked");
    }

The thing that strikes me as ODD. Is that this will work perfectly fine if I change:

string chk = "chk" + id.ToString();

To:

string chk = "chk";

But then of course we run into “multiple controls with the same ID”

My problem is getting this to work with unique ID’s! Another bit of ODD information that may help. If I take it out of a loop, and manually add a checkbox with a different ID it works as well. This is mind boggling 🙁

    chkDynamic = new CheckBox();
    chkDynamic.Text = "hey";
   // string chk = "chk" + id.ToString();

    chkDynamic.ID = "hey1";
    chkDynamic.CheckedChanged += new EventHandler(chkDynamic_CheckedChanged);
    Panel1.Controls.Add(chkDynamic);

    chkDynamic = new CheckBox();
    chkDynamic.Text = "hey";
   // string chk = "chk" + id.ToString();

    chkDynamic.ID = "hey2";
    chkDynamic.CheckedChanged += new EventHandler(chkDynamic_CheckedChanged);
    Panel1.Controls.Add(chkDynamic);

I have also debugged my program, and the values stored in the Session[“id”] are not null nor corrupt. Always holding value 0 and up!

Thanks for looking guys / gals. I’m really stuck on this!

PS – Sorry. There are no errors. The events just do not fire unless I hard code the ID’s.

  • 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-05-26T17:48:01+00:00Added an answer on May 26, 2026 at 5:48 pm

    Maybe you forget to reset the sesssion(“ID”), so when the page posts back the checkboxes are recreated with new ids. Since the checkbox-es are recreated on every postback, they need to have the same ID every time and if they don’t they are percepted as new controls and therefor the event handler is not called.

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

Sidebar

Related Questions

I have just create a very basic Dynamic Data web application using Entity Framework,
I am creating a very simple web part that accepts entry on a form
I have a servlet with an overridden doGet method in a Dynamic Web App
i have very simple problem. I need to create model, that represent element of
I have very long integer sequences that look like this (arbitrary length!): 0000000001110002220033333 Now
I have just created a mid-sized web-application using Java, a custom MVC framework, javascript.
We're building a site that will have very minimal code, it's mostly just going
I have a website in which the total dynamic content is very small (say
I have been creating a web app and am looking to expand. In my
I am building a very dynamic web-based application using a lot of Javascript to

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.