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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:05:36+00:00 2026-06-18T03:05:36+00:00

I have a boolean variable called CheckBoxActivated that I assign to true after validating

  • 0

I have a boolean variable called CheckBoxActivated that I assign to true after validating a user name and password.

string name = us.UserName;
string password = us.Password;

if (name.Equals(txtName.Text) && (password.Equals(txtPassword.Text)))
{
    CheckBoxAvtivated = true;

The strange thing is,after assigning ‘true’ to the variable I click another button and immediately it becomes ‘false’ which results in undesired behaviour.

protected void butNext_Click(object sender, EventArgs e)
{
    if (CheckBoxAvtivated)
    {
        pnlCheckBoxes.Visible = true;
        pnlUserCheckBoxValidation.Visible = false;
    }
    else
    {
        pnlCheckBoxes.Visible = false;
        pnlUserCheckBoxValidation.Visible = true;
    }

The state of the variable thus changes to false unexpectedly. Any reason why this could happen?

  • 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-18T03:05:38+00:00Added an answer on June 18, 2026 at 3:05 am

    The class level variables (global variables) in asp.net does not maintain state between postbacks you have to use viewstate if you want to keep the state between postbacks. ASP.NET is based on the HTTP protocol, which is stateless protocol and provides no means of storing a user’s data between requests

    To set in viewstate

    ViewState["CheckBoxAvtivated"] = "true";
    

    To get from viewstate

    bool CheckBoxAvtivated = bool.Parse(ViewState["CheckBoxAvtivated"].ToString());
    

    It is important to learn where to use viewstate and where it should not be used.

    The Role of View State

    View state’s purpose in life is simple: it’s there to persist state
    across postbacks. (For an ASP.NET Web page, its state is the property
    values of the controls that make up its control hierarchy.) This begs
    the question, "What sort of state needs to be persisted?" To answer
    that question, let’s start by looking at what state doesn’t need to be
    persisted across postbacks. Recall that in the instantiation stage of
    the page life cycle, the control hierarchy is created and those
    properties that are specified in the declarative syntax are assigned.
    Since these declarative properties are automatically reassigned on
    each postback when the control hierarchy is constructed, there’s no
    need to store these property values in the view state.

    From MSDN.

    Stateless protocol

    In computing, a stateless protocol is a communications protocol that
    treats each request as an independent transaction that is unrelated to
    any previous request so that the communication consists of independent
    pairs of requests and responses. A stateless protocol does not require
    the server to retain session information or status about each
    communications partner for the duration of multiple requests. In
    contrast, a protocol which requires the keeping of internal state is
    known as a stateful protocol.

    From Wikipedia

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

Sidebar

Related Questions

I have a function that needs to be called once a boolean variable is
I am creating an android application using Java. I have a boolean variable called
Suppose I have a text variable $$string . How can I write a boolean
I have a boolean variable called isTouchscreen and some on('hover', ...) events. If the
Suppose I have a struct called foo_boolean that contains some boolean values: struct foo_boolean
I have a boolean(primitive) variable in my bean. I need its value to be
I have three boolean variables. I need to check if all three are true
I know that SQL Server does not have boolean data type and your best
I have a boolean property in my ViewModel, named lets say IsNotSupported that is
I have a class called EditMapUtilities. Here are some class properties that I want

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.