title: ASP.NET private member field loses value on postback
body: <p>Consider the following code:</p>
  
  <pre><code>    public partial class TeacherControlPanel : System.Web.UI.Page
      {
          protected string username = string.Empty;
  
          protected void Page_Load(object sender, EventArgs e)
          {
              username = (string)Request.QueryString["username"];
  
              Ice_Web_Portal.BO.Teacher teacher = Ice_Web_Portal.BO.Teacher.GetTeacherByUsername(username);
  
              if (teacher != null)
              {
                  labUsername.Text = username;
                  labName.Text = teacher.TeacherName;
                  labTeacherCode.Text = teacher.TeacherCode;
  
                  Dept dept = teacher.Department;
  
                  if (dept != null)
                  {
                      labDepartment.Text = dept.DeptName;
                  }
              }
              else
              {
                  //labErrorMessage.Text = "No teacher found";
              }
          }
  
          protected void btnSendMail_Click(object sender, EventArgs e)
          {
              Response.Redirect(@"~/Teacher/TeacherComposeMail.aspx?username=mahabub" + username);            
          }
  }
  </code></pre>
  
  <p>In this code, when I am declaring 'username' as private, it is initialized to null after subsequent post backs.</p>
  
  <p>Why?</p>
  
  <p>What is the secret?</p>