title: NullReferenceException on ASP.NET PreviousPage Property
body: <p>I followed the directions from MSDN on transferring data between asp.net pages.</p>
  
  <p>But when using the 'PreviousPage' property to access the previous pages controls, I get a null ref exception that PreviousPage is not set to an instance of an object.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>public partial class Portal : System.Web.UI.Page
  {
      public string Username
      {
          get
          {
              return txt_User.Text;
          }
      }
  </code></pre>
  
  <p>And this is the submit button on initial page:</p>
  
  <pre><code>&lt;asp:Button ID="btn_Submit" runat="server" onclick="btn_Submit_Click" 
      PostBackUrl="~/Query.aspx"
  </code></pre>
  
  <p>Previous page property on second page:</p>
  
  <pre><code>    protected void Page_Load(object sender, EventArgs e)
      {
          Username = PreviousPage.Username; 
      }
  </code></pre>
  
  <p>As per MSDN instructions I also added this at the top of the second pages markup file:</p>
  
  <pre><code>&lt;%@ PreviousPageType VirtualPath="~/Portal.aspx" %&gt; 
  </code></pre>
  
  <p>Also note I have tried Server.Transfer to switch pages instead and that produces the same error. </p>
  
  <p>EDIT, here is using Server.Transfer on the initial page click event:</p>
  
  <pre><code> protected void btn_Submit_Click(object sender, EventArgs e)
      {
          Server.Transfer("Query.aspx"); 
      }
  </code></pre>
  
  <p>EDIT, button code without event handler:</p>
  
  <pre><code>&lt;asp:Button ID="btn_Submit" runat="server"
      PostBackUrl="~/Query.aspx"
      style="height: 26px" Text="Submit" /&gt;
  </code></pre>