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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:37:42+00:00 2026-06-17T16:37:42+00:00

I am having problems getting my page to maintain state. View state is enabled

  • 0

I am having problems getting my page to maintain state. View state is enabled by default but everytime I click a button it resets the form. This is the code I have

 protected void Page_Load(object sender, EventArgs e)
    {


        Levels loadGame = new Levels(currentGame);

        int [] gameNums =  loadGame.getLevelNums();
        int inc = 1;
        foreach(int i in gameNums){

            if (i != 0)
            {
                TextBox tb = (TextBox)FindControl("TextBox" + inc);
                tb.Text = i.ToString();
                tb.Enabled = false;
            }
            else {
                //leave blank and move to next box
            }

            inc++;
        }

This is the initial load

protected void NormalButton_Click(object sender, EventArgs e)
    {

        clearBoxes();//clear boxes first
        setCurrentGame("normal");//setting to normal returns normal answers
         Levels loadGame = new Levels(returnCurrentGame());

        int[] gameNums = loadGame.getLevelNums();
        int inc = 1;
        foreach (int i in gameNums)
        {

            if (i != 0)
            {
                TextBox tb = (TextBox)FindControl("TextBox" + inc);
                tb.Text = i.ToString();
                tb.Enabled = false;
            }
            else
            {
                //leave blank and move to next box
            }

            inc++;
        }

    }

Clicking this button changes the numbers in different boxes.

 protected void Button1_Click(object sender, EventArgs e)
    {

    }

Then I have this empty button but everytime I click it, it resets the form even though I havent set it to do anything yet. I would like the boxes to stay the same and I would also like to keep the objects alive. I’m not sure what I’m missing but please point me in the right direction. Thanks in advance

  • 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-17T16:37:42+00:00Added an answer on June 17, 2026 at 4:37 pm

    The Page_Load event occurs every time the page is loaded, including event-driven postbacks (button clicks, etc).

    It looks like initialization code is in your Page_Load, so when you click the button it runs again.

    There are two options:

    • Put everything that you want to happen only on the FIRST load in a n if statement:
    • Move your initialization to Page_Init.

    Code sample for the first option:

     protected void Page_Load(object sender, EventArgs e)
        {
          if(!Page.IsPostBack)  // Teis is the key line for avoiding the problem
          {
            Levels loadGame = new Levels(currentGame);
    
            int [] gameNums =  loadGame.getLevelNums();
            int inc = 1;
            foreach(int i in gameNums){
    
                if (i != 0)
                {
                    TextBox tb = (TextBox)FindControl("TextBox" + inc);
                    tb.Text = i.ToString();
                    tb.Enabled = false;
                }
                else {
                    //leave blank and move to next box
                }
    
                inc++;
            }
          }
         }
    

    Also, recommended reading: The ASP.NET Page Lifecycle

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

Sidebar

Related Questions

I am having problems getting at a click event of a button and am
I am having some problems getting my JS/JQ to fire in HTML5 page. Basically
I'm having problems getting my footer to stick to the bottom of the page
I've been having problems with gremlins from different encodings getting mixed into form input
I'm having a problem getting a simple ASP.NET webpage to display. The page contains
Im having problems getting at the HTML5 video tag with jQuery. Here is my
I am having problems getting the TextWrapping to work in this example. Can anyone
I am having problems getting my main content div to stretch to full height,
I am having problems getting JBoss to inject an environment variable value into a
I am having problems getting the 'ByAccount' aggregation to work in SQL Server Analysis

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.