ASP.NET Postback Class Members
Found this helpful article I thought I’d post..
http://webpaws.com/blog/2008/08/19/postback-in-aspnet-passing-variables-on-postback/
Basically I had a class variable in an ASP.NET and found it was getting lost on page post-back.. well all you have to do is put that object in the Viewstate object already created for you.
eg:
public partial class MyPage : System.Web.UI.Page
{
protected int MyInt;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
MyInt = 12345;
ViewState["MyKey"] = MyInt;
}
}
/*
This is called on a page post-back...
*/
protected void Event(object sender, EventArgs e)
{
//Get factor list from viewstate
MyInt = (int)ViewState["MyKey"];
//Go nuts
}
}