Consider a web form (aspx) wth an associated codefile (aspx.cs).
In the codefile, for instance, we have the following:
public partial class MyPage : System.Web.UI.Page {
int myint;
string mystring;
public void Page_Load(object sender, EventArgs e) {
...
if (!this.IsPostBack) {
this.myint = 2;
this.mystring = "Hello";
}
...
}
}
Can I expect to have the two variables everytime the page is posted back? I mean: are page class fields kept as part of the web form state?
Thankyou
No, these objects would be disposed at the end of the Page-Lifecycle.
If you want to persist them in ViewState you have to add them to it.
Objects that need to be stored in ViewState must be serializable.
Storing Simple Data Types in the ViewState
Storing Objects in View State