开发者

ASP.Net Update Panel with "The message received from the server could not be parsed"

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.

I found some code online to allow you to generate an .xls Excel file from a dataset.

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:

Sys.WebForms.PageRequestManagerParserErrorException The message received from the server could not be parsed.

I have tried the two versions of the header shown and have tried the completerequest() instead of response.end.

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?

Thanks in advance!

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=""" & filename & """")

    ' 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


Try this:

response.Flush();
HttpContext.Current.ApplicationInstance.CompleteRequest()

Do not call reposne.End()


check out this sample:

How to download/open the file that I retrive by server path?

it shows how to write a handler to DL a file.


Sorry, I know is a bit late, but found the answer right now.

Try with this answer. I resolve it doing what it is said here and it works perfectly

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜