开发者

Why are my private variables getting set to null?

开发者 https://www.devze.com 2023-04-01 21:44 出处:网络
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

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.

0

精彩评论

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

关注公众号