11021 : Im using Gantt_Asp but everytime I modify a timeitem I have a postback and I lose my f1.dataset values

Question

I’m using Gantt_Asp but everytime I modify a timeitem I have a postback and I lose my f1.dataset values

 

Answer

 

This is by design, the ASP.NET model is stateless and the SessionState is there to help you to handle that.

What you need to do is to, depending on your design criterias, is to cache the dataset you use and restore it for postback events. This is shown in the LetsBuild_ samples series available here http://www.plexityhide.nu/ajaxdemo/LetsBuild_ProjectPlanner.aspx

 

In short this is done like this:

 

    protected void Page_Load(object sender, EventArgs e)
    {

      if (Page.Session[“loaded_proj”] == null || (bool)(Page.Session[“loaded_proj”]) == false)
      {

 
 // OK, New user connect to your DB and fetch the data…

        f1.dataSet1.ReadXml(Page.MapPath(“.\\App_Data\\project.xml”));
        System.IO.MemoryStream ms = new System.IO.MemoryStream();
        f1.dataSet1.WriteXml(ms);
        Page.Session.Add(“thedata_proj”, ms);
        Page.Session.Add(“loaded_proj”, true);
      }
      else
      {
 // Returning user, get the cached dataset rather than fetching it again
        System.IO.MemoryStream ms = Page.Session[“thedata_proj”] as System.IO.MemoryStream;
        ms.Position=0;
        f1.dataSet1.ReadXml(ms);
      }
     
….
      }