Every variable defined in a class inheriting Web.UI.Page
will be destroyed at the end of the Page-Lifecycle(incl. controls and fields), hence it will be null
at postback if you don't reinitialize it.
One way to persist it across postbacks is to store it in a Session-variable.
You will find a complete list of all options on how to persist variables across postbacks here: http://msdn.microsoft.com/en-us/magazine/cc300437.aspx
- Application
- Cookies
- Form Post / Hidden Form Field
- QueryString
- Session
- New State Containers in ASP.NET
- Cache
- Context
- ViewState
- Web.config and Machine.config Files Conclusion
It's the nature of HTTP that it is stateless.