开发者

Retain IEnumerable<T> value during postback

开发者 https://www.devze.com 2022-12-23 08:55 出处:网络
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 o

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号