0

I have an asp.net page. In the code behind I set a few private variables in order to temporarily store some values. The variables are initially set by user selection from a listview. The variables are getting assigned the correct values. however, by the time the click event for a button is fired the variables are set to null.

what's going on and how do I fix it ?

2
  • @Dman - With a few days in the ASP.NET trenches you won't need any sample code to understand this question. Commented Aug 30, 2011 at 23:56
  • I can't believe this hasn't been asked before, but a search of [asp.net][state] doesn't find it. Commented Aug 30, 2011 at 23:57

2 Answers 2

7

Your code-behind classes don't magically remember variable values. Your page is effectively stateless -- either you have to recreate the state on each post-back or persist the values you want in Session or ViewData or in a database.

There is further information on how to implement state in ASP.NET here

Sign up to request clarification or add additional context in comments.

1 Comment

Ahhh - Got me at the start too - the stateless nature of ASP.NET
5

You can't store state in private member variables. See http://msdn.microsoft.com/en-us/library/75x4ha6s.aspx for places you can store state information.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.