title: Unable to disable button after post back asp.net
body: <p>I'm trying to create an web application where I have a button and if I click the button then a specified file will get downloaded and button should became disabled. Following code I use to do so</p>
  
  <pre><code>protected void btnDownload_Click(object sender, EventArgs e)
      {
          btnDownload.Enabled = false;
          string filepath = @"D:\SomeLayout.pdf";
          string filename = Path.GetFileName(filepath);
          Stream stream = null;
          try
          { 
              stream = new FileStream(filepath, FileMode.Open, FileAccess.Read, FileShare.Read);
              long bytesToRead = stream.Length;
              Response.ContentType = "application/octet-stream";
              Response.AddHeader("Content-Disposition", "attachment; filename=" + filename);
              while (bytesToRead &gt; 0)
              {
                  if (Response.IsClientConnected)
                  {
                      byte[] buffer = new Byte[10000];
                      int length = stream.Read(buffer, 0, 10000);
                      Response.OutputStream.Write(buffer, 0, length);
                      Response.Flush();
                      bytesToRead = bytesToRead - length;
                  }
                  else
                  {
                      bytesToRead = -1;
                  }
              }
          }
          catch (Exception ex)
          {
          }
          finally
          {
              if (stream != null)
              {
                  stream.Close();
              }
          }
      }
  </code></pre>
  
  <p>Once I click the button the file got downloaded but the button remains enable. I tried those all downloading code calling from other method but same problem occurs. But if I remove those code for download then after click the button it becomes disable. I'm not sure why the problem is and please help me to get a solution.</p>
  
  <p>The asp.net button I used </p>
  
  <pre><code>&lt;asp:Button ID="btnDownload" runat="server" Text="Download" OnClick="btnDownload_Click"/&gt;
  </code></pre>
  
  <p>Even if its possible by java script/jquery with meeting requirement please suggests me a solution.</p>