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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:23:32+00:00 2026-05-27T20:23:32+00:00

Ok so I am getting into programing in ASP.Net with C#. I am trying

  • 0

Ok so I am getting into programing in ASP.Net with C#. I am trying a very simple procedure but it is very buggy. So I have the following ASP code:

<asp:Button ID="Button1" runat="server" Text="Show Numbers" onclick="Button1_Click1" />
            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
            <asp:CheckBox ID="CheckBox1" runat="server" 
            oncheckedchanged="CheckBox1_CheckedChanged" />

I then have the following C# code behind it:

    int i = 0;
    List<int> Chosen = new List<int>();

    public void Page_Load(object sender, EventArgs e)
    {


    }
    public void Button1_Click1(object sender, EventArgs e)
    {
        if (i == 0)
        {
            TextBox1.Text = "Nothing here!";
        }
        else if (i == 1)
        {
            TextBox1.Text = Chosen[0].ToString();
        }
    }
    protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
    {
        if (CheckBox1.Checked == true)
        {
            Chosen.Add(1);
            i++;
            CheckBox1.Checked = true;
        }
        else if (CheckBox1.Checked == false)
        {
            Chosen.Remove(1);
            i--;
            CheckBox1.Checked = false;
        }
    }

The goal of the code is to have a checkbox on the screen. If it is checked I want to add the number 1 to my list (Chosen) also, when I push the button I want the textbox to display the number 1. If the checkbox becomes unchecked I want the number to get removed from the list and when I push the button I want it to display “Nothing here!”.

The problem is, sometimes it works and sometimes it doesn’t. For example if I click the box then the button it works. Then when I click the button again it says “Nothing Here!” it should stay as a 1.

  • 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-27T20:23:32+00:00Added an answer on May 27, 2026 at 8:23 pm

    You have to set AutoPostBack=true to the CheckBox control markup and also save that list into Session dictinary.

    List<int> Chosen;
    
    public void Page_Load(object sender, EventArgs e)
    {
      if(Sesstion["Chosen"]==null)
        {
          Session["Chosen"]=new List<int>();
        }
      Chosen = (List<int>)Session["Chosen"];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Most programing languages have 'include library into your code' function but where is function
I'm getting into ASP.NET (C# - I know it doesn't matter for this particular
I'm just getting into creating some WCF services, but I have a requirement to
I recently have been getting more into C++. I have done some (very minimal)
I am a student with a mainly electronics background getting into programing. The more
I have just been getting into low level programming (reading/writing to memory that sort
Thinking about getting into .net technology project management I've had plenty of experience with
I'm getting into more of a TDD workflow, and have a mix of MVC
Just getting started with Obj-C and iOS programming. I have some code that loads
I have a friend who is interested in getting into programming and is asking

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.