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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T06:20:08+00:00 2026-05-30T06:20:08+00:00

I’m building a simple game in an ASP.NET/VB.NET web app. The game has a

  • 0

I’m building a simple game in an ASP.NET/VB.NET web app. The game has a UI made up of several ImageButtons.

The web page’s code behind file holds an instance to the game object which will manage each turn taken by players.

Everything worked when the Game object’s methods were Shared.

The problem occurred after refactoring to make the game object work as an instance instead of a shared class. Now, when the action returns to the code behind, the instance of the game object is nothing.

I suspect that this has something to do with view state, but uh… Google hasn’t helped.

The code bits:

Public Class _Default
        Inherits System.Web.UI.Page

        Private _gamePanel As Panel
        Private _updatePanel as UpdatePanel
        Private _game as Game

        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

            If Not Page.IsPostBack Then

                'create a new instance of the game object on first loading page
                _game = New Game(width, height, cellsToWin)

            End If

            ' DisplayGameBoard() does the following:
            '  * Add images to the GameBoard panel inside of the GameBoardUpdatePanel
            '  * Attach click event handler to each image (addressOf located in this 
            '      code behind file
            '  * DisplayGameBoard() works fine the first time but fails on
            '      subsequent post backs because there is no game object instance
            Me.DisplayGameBoard()

        End Sub

(From the page directive)

Language="vb" 
AutoEventWireup="false" 
CodeBehind="Default.aspx.vb" 
Inherits="Game._Default" 
ValidateRequest="false" 
EnableEventValidation="false"
EnableViewState="true"

(update panel on the web page)

    <asp:UpdatePanel ID="GameBoardUpdatePanel" 
                     runat="server" 
                     UpdateMode="Conditional" 
                     RenderMode="Block" 
                     EnableViewState="true"
                     ViewStateMode="Enabled" 
                     ChildrenAsTriggers="true" >

        <ContentTemplate>

            <asp:Label ID="PlayerName"
                        runat="server"></asp:Label>

            <asp:Panel ID="GameBoard"
                        runat="server"
                        cssclass="gameBoard"></asp:Panel>

        </ContentTemplate>
    </asp:UpdatePanel>
  • 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-30T06:20:09+00:00Added an answer on May 30, 2026 at 6:20 am

    It’s not ViewState, it’s simply the life time of the _Default instance.

    You create an instance of the Game class and store that as a member of the page, and expect that instance to survive. The problem is that the instance of the page doesn’t survive.

    Each request for the page will result in a new instance of the _Default class to be created, and when the response is created the instance is thrown away. The reference to the instance of the Game class that you have stored in the page is also thrown away, and you lose any way to access it.

    If you want to keep the instance of the Game class, you can store it in the Session collection, which is user specific:

    If Not Page.IsPostBack Then
    
      'create a new instance of the game object on first loading page
      _game = New Game(width, height, cellsToWin)
      ' store the reference in the user session
      Session("game") = _game
    
    Else
    
      ' get the reference back from the user session
      _game = DirectCast(Session("game"), Game)
    
    End If
    

    However, you should be carful about how much you store in the user session. Normally objects that are created in a page are short lived (i.e. milliseconds), so they have a small impact on the server resources. Anything that you store in the user session will be extremely long lived in comparison. Consider how large the Game object is, and if you really need to keep the entire object, or if you can keep just the information needed to recreate it for each request.

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
Basically, what I'm trying to create is a page of div tags, each has
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm making a simple page using Google Maps API 3. My first. One marker
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

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.