title: How to solve Exception of type 'System.OutOfMemoryException' was thrown.Server Error in '/' Application
body: <p>I have a button on asp.net website that downloads the Excel file when I put certain values it points this error.</p>
  
  <p>My code behind is as follows </p>
  
  <pre><code> Protected Sub Button4_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button4.Click
      Response.Clear()
      Response.AddHeader("content-disposition", "attachment;filename=FileName.xls")
      Response.Charset = ""
      Response.ContentType = "application/vnd.xls"
      Dim stringWrite As New System.IO.StringWriter()
      Dim htmlWrite As System.Web.UI.HtmlTextWriter = New HtmlTextWriter(stringWrite)
      GridView6.RenderControl(htmlWrite)
      Response.Write(stringWrite.ToString())
      Response.[End]()
  End Sub
  </code></pre>
  
  <p>The button in aspx is as follows:</p>
  
  <pre><code>&lt;asp:Button ID="Button4" runat="server" Text="Extract RTD Raw Data" nclick="Button4_Click" 
                   BackColor="#FF9966"  CssClass="myButton" Font-Bold="True" 
                   Font-Italic="True" /&gt;
  </code></pre>
  
  <p>I am getting this stack trace. </p>
  
  <blockquote>
    <p><em>[OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.]<br>
    System.Web.Util.HttpEncoder.UrlDecode(Byte[] bytes, Int32 offset,
    Int32 count, Encoding encoding) +76<br>
    System.Web.HttpValueCollection.FillFromEncodedBytes(Byte[] bytes,
    Encoding encoding) +164<br>
    System.Web.HttpRequest.FillInFormCollection() +77 [HttpException
    (0x80004005): The URL-encoded form data is not valid.]<br>
    System.Web.HttpRequest.FillInFormCollection() +130<br>
    System.Web.HttpRequest.EnsureForm() +69<br>
    System.Web.HttpRequest.get_Form() +13<br>
    System.Web.HttpRequest.get_HasForm() +9800635<br>
    System.Web.UI.Page.GetCollectionBasedOnMethod(Boolean dontReturnNull)
    +95    System.Web.UI.Page.DeterminePostBackMode() +69    System.Web.UI.Page.ProcessRequestMain(Boolean
    includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
    +220</em></p>
  </blockquote>