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

The Archive Base Latest Questions

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

I am new to programming and have a problem . I have two buttons

  • 0

I am new to programming and have a problem . I have two buttons on an aspx page.
Both the buttons have runat="server" property and are inside <form runat="server" > tag

aspx code

<form id="form1" runat="server">
<asp:Button ID="btnGetData"  runat="server" onclick="btnGetData_Click" />
<asp:Button ID="btnShow" Text="Send" runat="server" onclick="btnShow_Click" />
</form>

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 as HTTP is statless. I read about Viewstate but it is not recommended when large amount of data is involved as results in significant processing delay.

Alternate is to use Session. Is there any use of IsPostBack page property here ?

Please guide how to implement Session to pass selected checkboxes from one button (GetData) click to other ie Show button.

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

    What you’ve run into is a fairly common problem, so might I recommend you use a repeater. Example:

    <asp:Repeater id="rptCheckboxes" runat="server">
    <ItemTemplate>
      <asp:CheckBox ID="cbxMessage" runat="server" Text="<%# Container.DataItem %>" />
      <br />
    </ItemTemplate>
    
    </asp:Repeater>
    

    And in code:

    protected void btnGetData_Click(object sender, EventArgs e)
    {
       headlines = masg.Split('*');
       rptCheckboxes.DataSource = headlines;
       rptCheckboxes.DataBind();
    }     
    
    protected void btnShow_Click(object sender, EventArgs e)
    {
       string newmsg = new string();
       foreach(RepeaterItem currentControl in rptCheckboxes.Items)
       {
           CheckBox currentCheckBox = currentControl.FindControl("cbxMessage");
    
           if(currentCheckBox != null && currentCheckBox.Checked)
           {
                 newmsg += cb[i].Text + '*';
           }
       }
    
       //This is a bad idea here, but we'll keep it for now
       Response.Write("<BR><BR><BR>" + newmsg);
    }
    

    Please note this is proof of concept, and hasn’t been tested to be functioning. The basics here is that during a postback, all of your controls are reset based on the aspx page and any logic you’ve written for that post. You should never dynamically add controls in the postback, and should only really do so using a placeholder in order to minimize risk of your ViewState becoming corrupt/invalid.

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

Sidebar

Related Questions

I have some problem in matlab since I was new in this programming language.
I am stuck with a programming problem: I have two Java projects, in my
I am fairly new to programming and trying to resolve this problem. I have
i am new kernel programming.i have been trying to load this driver program for
I'm very much new to programming and have been doing fairly well so far.
I am new to web programming...I have been asked to create a simple Internet
I'm new to PHP programming and have poor knowledge about it, but I want
I'm pretty new in iphone programming and have stumbled upon this issue which I
I am very new to python programming and have yet to buy a textbook
I am just new to programming in Unix and have a small issue that

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.