Friday 15 May 2015

Persist Server side Object Between PostBacks on ASP.NET

This is handy if you want a collection to persist between postback, good for general prototyping or testing.


Set the Item to static as shown below.



        private static MyData  DAL { get; set; }
        
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack)
                return;

            DAL = new MyData();
            grid1.DataSource = DAL.Customers;
            grid1.DataBind();
        }





No comments:

Post a Comment

Comments are welcome, but are moderated and may take a wee while before shown.