title: ASP.Net Update Panel with "The message received from the server could not be parsed"
body: <p>Okay, I've seen this asked in a couple of spots but never really got an answer that helped or that I understood.  I'm just starting back on ASP.net and am using VS 2010 on the 4.0 framework.</p>
  
  <p>I found some code online to allow you to generate an .xls Excel file from a dataset.</p>
  
  <p>The code is below, but when I run this code from a button outside of my ajax update panel it works perfectly.   If I execute the code from a button inside the update panel (where I need it to be) then I get the following:</p>
  
  <p>Sys.WebForms.PageRequestManagerParserErrorException The message received from the server could not be parsed.</p>
  
  <p>I have tried the two versions of the header shown and have tried the completerequest() instead of response.end.  </p>
  
  <p>Could someone explain to me why this doesn't work in the update panel and how I could make it work in the update panel?</p>
  
  <p>Thanks in advance!</p>
  
  <pre><code>Protected Sub ExportDataSetToExcel(ByVal ds As DataSet, ByVal filename As String)
      Dim response As HttpResponse = HttpContext.Current.Response
  
      ' first let's clean up the response.object
      response.Clear()
      response.Charset = ""
  
      ' set the response mime type for excel
      response.ContentType = "application/vnd.ms-excel"
      'response.ContentType = "application/octet-stream"
      response.AddHeader("Content-Disposition", "attachment;filename=""" &amp; filename &amp; """")
  
      ' create a string writer
      Using sw As New StringWriter()
          Using htw As New HtmlTextWriter(sw)
              ' instantiate a datagrid
              Dim dg As New DataGrid()
              dg.DataSource = ds.Tables(0)
              dg.DataBind()
              dg.RenderControl(htw)
              response.Write(sw.ToString())
              'HttpContext.Current.ApplicationInstance.CompleteRequest()
              response.End()
          End Using
      End Using
  End Sub
  </code></pre>