title: ASP.Net Page Not Posting Back - Reloading Instead
body: <p>I have a simple ASP.Net login page. When the login button is clicked, the page should post back and the even should be handled by my server-side event handler. Instead, the page simply reloads. <code>Page.IsPostBack</code> is <strong><code>false</code></strong>. </p>
  
  <p>I've put breakpoints in the Page_Load/Init (where applicable) handlers of the Master page, the ASPX page and the UserControl (ascx). When I hit the Login button, instead of getting a post back and having my event handler called, I simply get the page load as if it was a fresh request.</p>
  
  <p>But that's not the end of it! The login page takes a single query string parameter: <code>Login.aspx?id=123456</code>. The above failure occurs when using this parameter. However, if I enable <em>URL Rewriting</em> in order to make the query <code>Login/123456</code>, the error does <strong>not</strong> occur; I get a post back and my event handler is called in this instance. </p>
  
  <p>So why am I not getting the expected behaviour from my page? What about the rewritten URL is making the problem go away?</p>
  
  <p>Login Button is declared in <code>LoginUserControl.ascx</code>:</p>
  
  <pre><code>&lt;asp:Button ID="SubmitLinkButton" runat="server" Text='Log In' OnClick="SubmitLinkButton_Click"&gt;&lt;/asp:Button&gt;
  </code></pre>
  
  <p>And the handler in the code behind:</p>
  
  <pre><code>protected void SubmitLinkButton_Click(object sender, EventArgs e)
  {
      Authenticate();
  }
  </code></pre>
  
  <p><code>SubmitLinkButton_Click</code> is never called. :(</p>
  
  <p><strong>Edit (more code):</strong></p>
  
  <pre><code>//Page_Init on the Master page
  protected void Page_Init(object sender, EventArgs e)
  {
  
      if (HttpContext.Current.User.Identity.IsAuthenticated) 
      {
          try
          {
  
              if (SessionFacade.User != null)
              {
                  loginlabel.Text = "Logged in |";
                  LoginLink.Visible = true;
              }
          }
          catch
          {
              FormsAuthentication.SignOut();
              CacheFacade.RemoveSessionValues();
              Session.Abandon();
              Session.RemoveAll();
              HttpContext.Current.Response.Redirect("~/Login.aspx");
          }
      }
      else
      {
          loginlabel.Text = "";
          LoginLink.Visible = false;
      }
  }
  </code></pre>
  
  <p><strong>Page_Load</strong> on the ASPX page:</p>
  
  <pre><code>protected void Page_Load(object sender, EventArgs e)
  {
      if (this.IsPostBack.Equals(false))
      {
          /* Some business stuff that boils down to this: */
          Session["company"] = Request["company"];
      }
  }
  </code></pre>
  
  <p><strong>Page_Load</strong> on the Login Control:</p>
  
  <pre><code>protected void Page_Load(object sender, EventArgs e)
  {
  
      if (!Page.IsPostBack)
      {
          //honestly, there's no code here
      }
  
  }
  </code></pre>
  
  <p><strong>P.S</strong>: I need to keep the non-url-rewrite way of accessing the login page, because many users are still navigating to that URL.</p>
  
  <p><strong>P.P.S</strong>: Even if URL rewriting isn't enabled, the error still occurs.</p>