Using Response from within UpdatePanel

bcorbett

Active member
Joined
Oct 16, 2006
Messages
27
Programming Experience
Beginner
I get this error when the below function runs from within an Updatepanel:
"Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed"


VB.NET:
[FONT="Courier New"]Function CreatePDF(ByVal path As String)

Response.Clear()

Response.AppendHeader("content-disposition", "attachment; filename=sample.pdf")

Response.ContentType = "application/pdf"

Dim doc As New Document

pdf.PdfWriter.GetInstance(doc, Response.OutputStream)

doc.Open()

Dim img As Image = Image.GetInstance(path)

'img.Alignment = Image.ALIGN_CENTER

img.ScalePercent(20)

doc.Add(img)

doc.Close()[/FONT]
 
Add a PostBack trigger for the button. Select the UpdatePanel, find Triggers property, add PostBackTrigger and set the button id.

As this sends a user file no other reponse is returned to browser, so the other controls in updatepanel won't update because of this postback. For this reason you also don't need this button to be in a updatepanel.

Remember to end the response when you are finished writing the pdf document, else you will append the regular page response to the end of the pdf file.
VB.NET:
Response.End()
 
Back
Top