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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T22:18:35+00:00 2026-06-18T22:18:35+00:00

i have an issue with creating an object in ASP.net My Page Load function

  • 0

i have an issue with creating an object in ASP.net

My Page Load function is:

public partial class hangMen : System.Web.UI.Page
{
abc ltr;
Words word = null;
static Label [] lbl = null;
static Button[] btn = null;
Game game;

protected void Page_Load(object sender, EventArgs e)
{

        if (Page.IsPostBack)
        {
            show_current_word();
            SetBord();

        }
        else
        {
            SetBord();
            SetWords(); 


        }

}
}

My issue is:
Iam not sure where should i put the
game = new Game();

if i put it in the else part so i get null reference exception.
and i also dont want to create this oject every post-back.

this object count the player score and the times that click “Hint” and make a wrong

any ideas??

  • 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-18T22:18:37+00:00Added an answer on June 18, 2026 at 10:18 pm

    If I understand correctly, you want to keep a instance of the Game object through postbacks…

    For that I recommend you use the Session object

    Saving to the Session:

    Session["GameObj"] = game;
    

    Restoring it in next postback:

    protected void Page_Load(object sender, EventArgs e)
    {
       if (Session["GameObj"] != null)
       {
           game = (Game) Session["GameObj"];
       }
        ...
    

    Of course there are other options such as saving it in the ViewState. You should read about them and see which one better suits your needs

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

Sidebar

Related Questions

I am creating a web application in ASP.net/VB.NET and I have an issue with
When making calls to a webservice from an asp.net web application, to avoid creating
in my ASP.NET application, I am creating a new class to handle errors in
I have an object: public class TestEvent : IEvent { private string _id; public
I have an asp.net page that needs to populate a treeview based on a
I have one leak issue in my application, i am creating a autorelease object
I have an ASP.NET 2.0 web service and am using it in (among other
I have run into an issue when creating a object type in Oracle 10g
If I'm creating a class, and I will load an object of that class
I am working on creating a custom membership class for my asp.net project. In

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.