Why are my private variables getting set to null?
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 se开发者_如何学JAVAt to null.
what's going on and how do I fix it ?
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
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.
精彩评论