I have an IEnumerable< T> which is declared on the page like this:
IEnumerable< Person> person;
When the page postsback, the person list i开发者_如何转开发s null. How can I retain the values of person list without declaring it as static? Sr. devs in my company say that you should not declare the list as static.
Sr. Devs are right. No static (rather read C# basics - really bad idea).
Variables in general do not preserve between postbacks. Read up on using the SESSION or the VIEWSTATE for storing information for a user.
You need to know more about page life-cycle. When page is rendered to the client its object is thrown away. If you have any field in your page you need to initialize it explicitely every time before you are going to use it.
精彩评论