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??
If I understand correctly, you want to keep a instance of the
Gameobject through postbacks…For that I recommend you use the Session object
Saving to the Session:
Restoring it in next postback:
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