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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:34:24+00:00 2026-06-15T17:34:24+00:00

I am stuck with a problem which I have reduced to code below .

  • 0

I am stuck with a problem which I have reduced to code below . I have two buttons on an aspx page.
Both the buttons have runat="server" property and are inside <form runat="server" > tag

btnGetData

 protected void btnGetData_Click(object sender, EventArgs e)
 {
            headlines = masg.Split('*');
            //Response.Write(headlines.Length);
            cb = new CheckBox[headlines.Length];

            for (int i = 0; i < headlines.Length; i++)
            {
                cb[i] = new CheckBox();

                cb[i].Text = headlines[i];
                Literal br = new Literal();
                br.Text = "<br/>";
                Form.Controls.Add(cb[i]);
                Form.Controls.Add(br);
            }

 }     

On clicking Get Data button , multiple checkboxes are generated with associated text .

I click on some of the checkboxes and then click on Show button which IF WORKS CORRECTLY should combine selected checboxes text into single string and display it.

btnShow

protected void btnShow_Click(object sender, EventArgs e)
{



            for (int i = 0; i < headlines.Length; i++)
            {
                if (cb[i].Checked)
                    newmsg += cb[i].Text + '*';
            }
            Response.Write("<BR><BR><BR>" + newmsg);

}

But once I click on GetData button , the checkboxes are lost as they don’t persist . I read about SESSION variables but can’t figure out how to apply them .
I have declared below variables as global so that they can be accessed throughout the page.

CheckBox[] cb;
string[] headlines;
string masg;

Please help with code .Please provide me with inputs in code. I will refine my question if I am not able to make something clear.

  • 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-15T17:34:24+00:00Added an answer on June 15, 2026 at 5:34 pm

    You need to recreate dynamically created controls on every postback(in Page_Init or Page_Load) due to the statelessness of HTTP. You need to know what you have to recreate. Therefore you can save the number of already created CheckBoxes in a ViewState variable.

    You only need to assign the same IDs as before and add them in Page_Load at the latest. If you know the number of controls to create you can derive the ID from the counter variable by appending it to the control-id.

    Recommandable readings:

    • TRULY Understanding Dynamic Controls
    • Page-Lifecycle

    Or you use one of the builtin Data-Bound Control like Repeater that do this automatically. You only have to set their DataSource and call DataBind().

    Here are answers of me on similar questions with implementation details:

    • C#
    • VB.NET (+ C#)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a small problem here which I really am quite stuck in right
I am stuck in a problem which is related to ios 6. i have
I'm stuck with the JavaScript code I am using for solving a problem which
I'm having a strange problem with ZeroMQ, in which some messages get stuck, and
I got stuck with this problem. I wrap two tables inside of a h:form.
I'm stuck on a problem I really don't know how to solve: I have
I have a problem which I like and I love to think about solutions,
I'm a bit stuck on a problem which I can't solve, I performed investigation
I am stuck with a map View problem for which I was surfing the
i stuck with a problem which is really important i guess. In a simple

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.