title: session variable object gets deleted on postback - ASP.NET
body: <p>I have made something like the following code:</p>
  
  <pre><code>protected void Page_Load(object sender, EventArgs e)
  {
     Label1.Text = Session["loginid"].ToString();
  }
  
  protected void delete_click(object sender, EventArgs e)
  {
      delete("mail1",Session["loginid"]);
  }
  
  private int delete(string mailid, string user)
  {
   System.IO.Directory.Delete(Server.MapPath(@"~\files\" + user + @"\" + mailid), true);
  }
  </code></pre>
  
  <p>When i press the delete button, everything works fine and the folder gets deleted.
  but after that when page postbacks again then a
  NullRefrenceException is raised at 
   Label1.Text = Session["loginid"].ToString();</p>
  
  <p>why is it happening...??</p>
  
  <p>When I am not using this Directory.Delete() method everything is working fine and session variables are not set to null.</p>
  
  <p>When I traced my application I found that After Directory.Delete() method Session variables were intact and I was able to use those session variables in the processing after Directory.Delete().</p>
  
  <p>But as soon as the page postbacks all session variables are set to null.
  And this problem doesn't appear when i m not using this delete() method.</p>
  
  <p>The folder I m deleting is in my project's folder.
  I m running this website using Visual Studio.</p>
  
  <p>Please help.</p>