Wednesday, March 21, 2012

UpdatePanel and Response.Write / Response.TransmitFile

I think I may be missing something obvious here, there are many posts about not using Response.Write to write to the page within an UpdatePanel. But how can I generate and transmit a file to the client while inside an UpdatePanel?

For example, a page might be laid out like this:

<Updatepanel>
<Selection Controls>
<Button>
<Table/>
</UpdatePanel>

The purpose of the Button is to allow the client to simply export the data from the table:

Protected Sub Button_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button.Click
CreateMyFile()
Response.Clear()
Response.ContentType = "text/plain"
Response.AddHeader("content-disposition", "attachment; filename=HelloWorld.txt")
Response.TransmitFile("HelloWorld.txt")
Response.End()
End Sub

Obviously I can move the Button triggering the download outside the UpdatePanel and use one UpdatePanel for the Selection Controls and another for the Table, but is there a better way to accomplish what I'm trying to do that I'm overlooking?

Thanks,

Hi.

you can use this code in page_load.

 ScriptManager.GetCurrent(this.Page).RegisterPostBackControl(Button);

No comments:

Post a Comment