“the j stands for Jangle”
about me | wordpress plugins | jQuery plugins

25 April, 2009

ASP.NET Postback Class Members

Filed under: ASP.NET,Web Development — Tags: , , — John @ 8:03 pm

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
	}
}

No Comments »

:(

RSS feed for comments on this post. TrackBack URL

Leave a comment